添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

I have a POST request API call to add a post with title, text and multiple image in the format like below:

"title" : "post title", "text" : "post text", "fileName" : ["S3-file-image1.png", "S3-file-image2.png", "S3-file-image3.png"...]

So, I created a form to add title, text and choose multiple image file. Now, in html i can directly bind form data for title and text but for image, first I am uploading selected images to S3 bucket and retrieving the S3 image file location. Here is the code I have used for uploading image

     postData = {
          "title" : "post title",
          "text" : "post text"
     postData.fileName = [];       // Here i am creating fileName array with empty
     const bucket = new S3(
            accessKeyId: 'my-access-key-id',
            secretAccessKey: 'secret-access-key',
            region: 'ap-region'
      const params = {
        Bucket: 'Bucket-Name',
        Key: fileName,
        Body: file,
        ACL: 'public-read',
        ContentType: fileType,
        ServerSideEncryption: 'AES256'
      bucket.upload(params).on('httpUploadProgress', (evt) => {
        console.log(evt.loaded + ' of ' + evt.total + ' Bytes');
      }).send(
        (err, data) => {
          if (err) {
            console.log('There was an error uploading your file: ', err);
            return false;
          console.log('Successfully uploaded file.', data);
          postData.fileName.push(btoa(data.Location));       // Here I am pushing uploaded file location to postData.
      consol.log(postData.fileName);       // It gives empty array with 'i' (Value below was evaluated just now) on next to array. On tapping arrow of that empty array gives the result I required.
      const body = JSON.stringify(postData);
      return this.http.post<any>(this.url + groupId + '/post/add', body, {headers: headersType});

Because of pushing location name to empty array on post request it is taking only empty array as the response. How can i get uploaded image location on postData