When I try to upload an image into a bucket on the server side I'm getting the error above. I checked using the debugger that the file parameter contains the file's path and not the folder's path. Here's the code :
function uploadFile(file, directory) {
return new Promise((resolve, reject) => {
try {
const bucket = storage.bucket(BUCKET_NAME);
const bucketFile = bucket.file(directory ? `${directory}/${file.originalname}` : file.originalname);
const blobStream = bucketFile.createWriteStream();
blobStream.on('error', err => {
const status = err.status || 500;
console.log(err, status);
reject(err);
});
blobStream.on('finish', async () => {
// The public URL can be used to directly access the file via HTTP.
await bucketFile.makePublic();
const publicUrl = `/${bucket.name}/${bucketFile.name}`;
resolve(publicUrl);
});
blobStream.end(file.buffer);
} catch (err) {
reject(err);
}
});
}
Can you help me?
When I try to upload an image into a bucket on the server side I'm getting the error above. I checked using the debugger that the file parameter contains the file's path and not the folder's path. Here's the code :
function uploadFile(file, directory) {
return new Promise((resolve, reject) => {
try {
const bucket = storage.bucket(BUCKET_NAME);
const bucketFile = bucket.file(directory ? `${directory}/${file.originalname}` : file.originalname);
const blobStream = bucketFile.createWriteStream();
blobStream.on('error', err => {
const status = err.status || 500;
console.log(err, status);
reject(err);
});
blobStream.on('finish', async () => {
// The public URL can be used to directly access the file via HTTP.
await bucketFile.makePublic();
const publicUrl = `https://storage.googleapis./${bucket.name}/${bucketFile.name}`;
resolve(publicUrl);
});
blobStream.end(file.buffer);
} catch (err) {
reject(err);
}
});
}
Can you help me?
Share Improve this question edited Apr 19, 2021 at 13:44 Prime 2,8492 gold badges10 silver badges24 bronze badges asked Apr 19, 2021 at 13:42 andrcandrc 952 silver badges11 bronze badges 2-
Run it with
strace
to see which exact syscall causes theEISDIR
and what its path argument was - or, if you get a stack trace, add some log output directly at thefs
call which causes the error. Then based on what you find, think about how that can be - I can't say without knowing what you found first. :) – CherryDT Commented Apr 19, 2021 at 13:46 -
The error hints on you reaching a directory instead of a file in your bucket, so I would log the values of
directory
andfile.originalname
to check if they are correct, could you do that and share this information? – Rafael Lemos Commented Apr 20, 2021 at 11:57
1 Answer
Reset to default 5The path of the file was right. But the path to the credentials was wrong
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745401574a4626127.html
评论列表(0条)