Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception when uploading in ios #45

Open
amanthegreatone opened this issue Mar 4, 2017 · 3 comments
Open

Exception when uploading in ios #45

amanthegreatone opened this issue Mar 4, 2017 · 3 comments

Comments

@amanthegreatone
Copy link
Contributor

amanthegreatone commented Mar 4, 2017

Hi,

getting an exception when trying to upload in ios. The same code works perfectly on android device.

screen shot 2017-03-04 at 12 07 23 pm


const subscribeWithUpdateState = (id, typeKey, attachment) => {
  console.log("subscribeWithUpdateState", "id", id, "typeKey", typeKey);

  transferUtility.subscribe(id, (err, task) => {
    if(err){
      task.errMessage = err;
    }
    else{
      if(task.state === "completed"){
        console.log("task uploaded", task, "attachment", attachment);

        //update the offline attachment for successful upload
        updateAttachmentUploaded(attachment);

        //dispatch action to update the attachment in the store

      }//end if upload task completed
    }
  });

};//end of subscribeWithUpdateState

export function uploadAttachment(attachment) {

  //initialize s3 transferUtility
  transferUtility.setupWithCognito(S3Options)
    .then( (result) => {
      console.log("s3 setup result", result);

      //compress the file
      let imagePath = `${dirPicutures}/${attachment.s3_key}`;
      let compressedImagePath = `${dirPicuturesCompressed}/${attachment.s3_key}`;

      compressImage(imagePath, compressedImagePath)
      .then( (imageResized) => {
        console.log("imageResized boolean", imageResized);

        //upload to s3
        const contentType = "image/jpg";

        transferUtility.upload({
          bucket: BucketName,
          key: attachment.s3_key,
          file: compressedImagePath,
          meta: { "Content-Type": contentType }
        }).then( (task) =>  {
          console.log("task uploding:", task);

          //subscribe to the s3 upload status and pass in the attachment to update once upload successful
          subscribeWithUpdateState(task.id, "uploadTasks", attachment);

        })//end promise upload to s3
        .catch( (error) => console.log("upload error:", error) );

      })//end promise successful for compressImage
      .catch( (error) => console.log("imageResized error", error) );

    })//end promise successful s3 cognito setup
    .catch( (error) => console.log("s3 setup error", error) );

}//end of uploadAttachment

iPhone 6 simulator / iphone 4 device
RN 0.40.0
react-native-s3 0.0.24

@jhen0409
Copy link
Member

jhen0409 commented Mar 5, 2017

It's valid bucket name syook-saas-dev/cache? The bucket name should be DNS-compliant.

@amanthegreatone
Copy link
Contributor Author

yes the bucket is valid. The same code is working on android device perfectly.

@amanthegreatone
Copy link
Contributor Author

can someone help me troubleshoot this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants