Guest User

Untitled

a guest
Aug 10th, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. const s3 = new aws.S3();
  2.  
  3. const s3Params = {
  4. Bucket: bucket,
  5. Key: fileName,
  6. Expires: 60,
  7. ContentType: 'image/jpeg',
  8. ACL: 'public-read'
  9. };
  10.  
  11. return s3.getSignedUrl('putObject', s3Params);
  12.  
  13. var file = {
  14. uri: game.pictureToSubmitUri,
  15. type: 'image/jpeg',
  16. name: 'image.jpg',
  17. };
  18.  
  19. const xhr = new XMLHttpRequest();
  20. var body = new FormData();
  21. body.append('file', file);
  22. xhr.open('PUT', signedRequest);
  23. xhr.onreadystatechange = () => {
  24. if(xhr.readyState === 4){
  25. if(xhr.status === 200){
  26. alert('Posted!');
  27. }
  28. else{
  29. alert('Could not upload file.');
  30. }
  31. }
  32. };
  33. xhr.send(body);
  34.  
  35. <Code>SignatureDoesNotMatch</Code>
  36. <Message>
  37. The request signature we calculated does not match the signature you provided. Check your key and signing method.
  38. </Message>
  39.  
  40. function uploadFile(file, signedRequest, url) {
  41. const xhr = new XMLHttpRequest();
  42. xhr.open('PUT', signedRequest);
  43. xhr.onreadystatechange = function() {
  44. if (xhr.readyState === 4) {
  45. if(xhr.status === 200) {
  46. alert(url);
  47. } else {
  48. alert('Could not upload file.');
  49. }
  50. }
  51. };
  52. xhr.send(file);
  53. };
  54.  
  55. import RNFetchBlob from 'rn-fetch-blob'
  56.  
  57. const preSignedURL = 'pre-signed url'
  58. const pathToImage = '/path/to/image.jpg' // without file:// scheme at the beginning
  59. const headers = {}
  60.  
  61. RNFetchBlob.fetch('PUT', preSignedURL, headers, RNFetchBlob.wrap(pathToImage))
Add Comment
Please, Sign In to add comment