Почему, когда я загружаю изображение в корзину S3, мой API не работает? - PullRequest
0 голосов
/ 30 мая 2019

Я использую Vue / NuxtJ в качестве внешнего интерфейса и .net core 2.1 в качестве внутреннего.Мне нужно отправить изображение в свой бэкэнд и загрузить в S3 Bucket.Это хорошо работает в localhost, однако, когда я публикую свой API, начинают выдавать ошибки, например, файлы становятся больше и повреждены, и это происходит только с изображениями.Кто-то может помочь?

передний конец

async onUpload() {
      this.isNew = true;
      this.showProgess = true;
      debugger;
      const file = new FormData();
      console.log(this.selectedFile.size);
      file.append("file", this.selectedFile, this.selectedFile.name);
      file.append("fileType", 0);
      await this.$axios
        .$post(process.env.API_URL + `/PlanImages`, file, {
          headers: {
            "Content-Type": "multipart/form-data"
          },
          onUploadProgress: function (progressEvent) {
            this.uploadPercentage = parseInt(
              Math.round((progressEvent.loaded * 100) / progressEvent.total)
            );
          }
        })
        .then((response) => {
          if (response.result.success) {
            this.uploadSuccess = true;
            this.saveDisable = false;
            this.uploadDisable = true;
            this.editedItem.fileUrl = response.result.fileURL;
            console.log(response);
          }
          this.showProgess = false;
          console.log("call one");
        })
        .catch((error) => {
          this.showProgess = false;
          console.log(error);
        });
    },

задний конец

 public async Task<UploadPhotoModel> UploadPhoto(IFormFile files, string bucket)
        {
            var test = files.Length;
            // connecting to the client
            var client = new AmazonS3Client("accessKey", "accessSecret", Amazon.RegionEndpoint.CACentral1);

            var fileName = Guid.NewGuid().ToString() + files.FileName;


            using (var newMemoryStream = new MemoryStream())
            {
                files.CopyTo(newMemoryStream);

                var uploadRequest = new TransferUtilityUploadRequest
                {
                    InputStream = newMemoryStream,
                    Key = fileName,
                    BucketName = "bucket",
                    PartSize = 6291456, // 6 MB.
                    CannedACL = S3CannedACL.PublicRead
                };

                var fileTransferUtility = new TransferUtility(client);
                await fileTransferUtility.UploadAsync(uploadRequest);
            }


...