This repository has been archived by the owner on Dec 20, 2024. It is now read-only.
storj implementation using express #541
Locked
jyotiprakash-m
started this conversation in
Show & Tell
Replies: 2 comments
-
@swarnava any idea on the above issue? thanks |
Beta Was this translation helpful? Give feedback.
0 replies
-
Vercel provide only Read only file system so you won't be able to write files in directory. Have you tried consulting with Storj team? |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I tried to create an express backend serverless application with storj to upload document . When i try to call the get api the following error is showing in the production log
[GET] /api/storj/295deaeb-5638-4589-9fab-00166e3c3b32
22:51:20:27
2022-04-04T17:21:21.011Z undefined ERROR Error: EROFS: read-only file system, mkdir '/var/task/uploads'
at Object.mkdirSync (fs.js:1013:3)
at Function.sync (/var/task/node_modules/mkdirp/index.js:72:13)
at new DiskStorage (/var/task/node_modules/multer/storage/disk.js:21:12)
at module.exports (/var/task/node_modules/multer/storage/disk.js:65:10)
at new Multer (/var/task/node_modules/multer/index.js:15:20)
at multer (/var/task/node_modules/multer/index.js:95:12)
at Object. (/var/task/api/index.js:7:16)
at Module._compile (internal/modules/cjs/loader.js:1085:14)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
at Module.load (internal/modules/cjs/loader.js:950:32) {
errno: -30,
syscall: 'mkdir',
code: 'EROFS',
path: '/var/task/uploads'
}
2022-04-04T17:21:21.607Z undefined ERROR Error: EROFS: read-only file system, mkdir '/var/task/uploads'
at Object.mkdirSync (fs.js:1013:3)
at Function.sync (/var/task/node_modules/mkdirp/index.js:72:13)
at new DiskStorage (/var/task/node_modules/multer/storage/disk.js:21:12)
at module.exports (/var/task/node_modules/multer/storage/disk.js:65:10)
at new Multer (/var/task/node_modules/multer/index.js:15:20)
at multer (/var/task/node_modules/multer/index.js:95:12)
at Object. (/var/task/api/index.js:7:16)
at Module._compile (internal/modules/cjs/loader.js:1085:14)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
at Module.load (internal/modules/cjs/loader.js:950:32) {
errno: -30,
syscall: 'mkdir',
code: 'EROFS',
path: '/var/task/uploads'
}
RequestId: 445353a2-2e59-4258-bace-b19c77b6b7b2 Error: Runtime exited with error: exit status 1
Runtime.ExitError
** Below is the code snippet i tried **
const express = require("express");
const bodyParser = require("body-parser");
const cors = require("cors");
const helmet = require("helmet");
const morgan = require("morgan");
const multer = require("multer");
const upload = multer({ dest: "uploads/" });
const PORT = process.env.PORT || 3001
const S3 = require("aws-sdk/clients/s3");
const fs = require("fs");
require("dotenv").config();
const mongoose = require("mongoose")
// Monogdb connection
const documentInfo = require("../models/documentInfoModel")
mongoose.connect(process.env.MONGODB_URI, {
useNewUrlParser: true,
useUnifiedTopology: true,
}).then(res => console.log("DB Connected")).catch(err => console.log(err))
const accessKeyId = process.env.ACCESS_KEY_ID;
const secretAccessKey = process.env.SECRET_ACCESS_KEY;
const endpoint = process.env.ENDPOINT;
const s3 = new S3({
accessKeyId,
secretAccessKey,
endpoint,
s3ForcePathStyle: true,
signatureVersion: "v4",
connectTimeout: 0,
httpOptions: { timeout: 0 },
});
// defining the Express app
const app = express();
// adding Helmet to enhance your API's security
app.use(helmet());
// using bodyParser to parse JSON bodies into JS objects
app.use(bodyParser.json());
app.use(
bodyParser.urlencoded({
extended: false,
})
);
// enabling CORS for all requests
app.use(cors());
// app.use(upload.array());
// adding morgan to log HTTP requests
app.use(morgan("combined"));
app.post(
"api/storj/upload",
upload.single("doc"),
async function (req, res, next) {
try {
console.log(req.file);
console.log(req.body);
const userDocuments = await documentInfo.find({ email: req.body.email })
if (userDocuments.length < 5) {
const file = fs.readFileSync(req.file.path);
const params = {
Bucket: "demo-bucket",
Key: req.body.key,
Body: file,
};
const result = await s3
.upload(params, {
partSize: 64 * 1024 * 1024,
})
.promise();
);
app.get("api/storj/:key", async (req, res) => {
const params = {
Bucket: "demo-bucket",
Key: req.params.key,
};
const url = s3.getSignedUrl("getObject", params);
console.log("url", url);
});
module.exports = app;
Please answer my doubts . For reference the github link for this application is https://github.com/jyotiprakash-m/serverless-nextjs
Beta Was this translation helpful? Give feedback.
All reactions