javascript - EISDIR - EISDIR: illegal operation on a directory, read - Stack Overflow

When I try to upload an image into a bucket on the server side I'm getting the error above. I chec

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 the EISDIR and what its path argument was - or, if you get a stack trace, add some log output directly at the fs 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 and file.originalname to check if they are correct, could you do that and share this information? – Rafael Lemos Commented Apr 20, 2021 at 11:57
Add a ment  | 

1 Answer 1

Reset to default 5

The path of the file was right. But the path to the credentials was wrong

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745401574a4626127.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信