【发布时间】:2017-12-19 06:42:43
【问题描述】:
我有这个云功能,我写的上传文件到谷歌云存储:
const gcs = require('@google-cloud/storage')({keyFilename:'2fe4e3d2bfdc.json'});
var filePath = file.path + "/" + file.name;
return bucket.upload(filePath, {
destination: file.name
}).catch(reason => {
console.error(reason);
});
我使用formidable 来解析上传的文件,并尝试记录上传文件的属性,看起来不错;它已上传到临时目录'/tmp/upload_2866bbe4fdcc5beb30c06ae6c3f6b1aa/ 但是当我尝试将文件上传到 gcs 时出现此错误:
{ Error: EACCES: permission denied, stat '/tmp/upload_2866bbe4fdcc5beb30c06ae6c3f6b1aa/thumb_ttttttt.jpg'
at Error (native)
errno: -13,
code: 'EACCES',
syscall: 'stat',
path: '/tmp/upload_2866bbe4fdcc5beb30c06ae6c3f6b1aa/thumb_ttttttt.jpg' }
我正在使用这个 html 表单来上传文件:
<!DOCTYPE html>
<html>
<body>
<form action="https://us-central1-appname.cloudfunctions.net/uploadFile" method="post" enctype="multipart/form-data">
Select image to upload:
<input type="file" name="fileToUpload" id="fileToUpload">
<input type="submit" value="Upload Image" name="submit">
</form>
</body>
</html>
【问题讨论】:
-
您似乎没有获得执行此操作的正确权限。
-
是的,我无法访问我上传的临时文件。
标签: javascript firebase google-cloud-storage google-cloud-functions