TypeError:无法读取未定义的属性'byteLength'-AWS S3上载 [英] TypeError: Cannot read property 'byteLength' of undefined - AWS S3 Upload

查看:25
本文介绍了TypeError:无法读取未定义的属性'byteLength'-AWS S3上载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从Reaction客户端上传AWS S3照片,遇到以下错误:

TypeError: Cannot read property 'byteLength' of undefined

我假设Upload对象中有缺陷,但我认为S3/Cogito配置可能有问题,因为我在调用s3.listObjects时收到了相同的错误。我正在关注这些文档-https://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/s3-example-photo-album-full.html

有什么想法吗?

uploadPhoto() {
        const files = document.getElementById("photoUpload").files;
        if (!files.length) {
          return alert("Please choose a file to upload first.");
        }
        const file = files[0];
        const fileName = file.name;
        const albumPhotosKey = encodeURIComponent('screenshots') + "/";
      
        const photoKey = albumPhotosKey + fileName;
        
        // Use S3 ManagedUpload class as it supports multipart uploads
        
        const upload = new AWS.S3.ManagedUpload({
            params: {
              Bucket: <Bucket Name>,
              Key: fileName,
              Body: file
            }
          });

        const promise = upload.promise();
      
        promise.then(
          function(data) {
            alert("Successfully uploaded photo.");
            console.log('UPLOAD: ', data)
          },
          function(err) {
              console.log('ERROR: ', err)
            // return alert("There was an error uploading your photo: ", err.message);
          }
        );
      }

推荐答案

我在Reaction本机应用程序中遇到此错误。我可以通过关闭开发工具网络检查器来修复它。

这篇关于TypeError:无法读取未定义的属性&#39;byteLength&#39;-AWS S3上载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆