|
17 | 17 |
|
18 | 18 | return service;
|
19 | 19 |
|
20 |
| - function getPresignedURL(body) { |
21 |
| - // var deferred = $q.defer(); |
22 |
| - console.log('body: ', body) |
23 |
| - // return api.all('submissions').post('photoUploadUrl', {contentType: file.type}) |
| 20 | + function getPresignedURL(body, files) { |
| 21 | + console.log('body to get presigned url: ', body) |
24 | 22 |
|
25 | 23 | return api.all('submissions').customPOST(JSON.stringify({param: body}))
|
26 | 24 | .then(function(response) {
|
27 |
| - console.log('POST Response: ', response); |
28 |
| - // deferred.resolve({ |
29 |
| - // preSignedURL: response.preSignedURL, |
30 |
| - // token: response.token, |
31 |
| - // file: file, |
32 |
| - // userHandle: userHandle |
33 |
| - // }); |
| 25 | + console.log('POST Response: ', response.plain()); |
| 26 | + |
| 27 | + uploadSubmissionFileToS3(response.data.files, files); |
34 | 28 | })
|
35 | 29 | .catch(function(err) {
|
36 | 30 | console.log(err);
|
37 | 31 | $log.info('Error getting presigned url');
|
38 |
| - toaster.pop('error', 'Whoops!', 'There was an error uploading your profile image. Please try again later.'); |
39 |
| - // deferred.reject(err); |
| 32 | + toaster.pop('error', 'Whoops!', 'There was an error uploading your submissions. Please try again later.'); |
40 | 33 | });
|
41 |
| - |
42 |
| - // return deferred.promise; |
43 | 34 | }
|
44 | 35 |
|
45 |
| - function uploadSubmissionFileToS3(/* something that has file*/) { |
46 |
| - var file; |
47 |
| - var S3RequestOptions = { |
48 |
| - url: 'preSignedURL', |
49 |
| - method: 'PUT', |
50 |
| - headers: {}, |
51 |
| - data: 'File Object' |
52 |
| - }; |
| 36 | + function uploadSubmissionFileToS3(filesWithPresignedURL, files) { |
| 37 | + var promises = filesWithPresignedURL.map(function(fileWithPresignedURL) { |
| 38 | + var S3RequestOptions = { |
| 39 | + url: fileWithPresignedURL.preSignedUploadUrl, |
| 40 | + method: 'PUT', |
| 41 | + // headers: {}, |
| 42 | + |
| 43 | + // The file's type is the key, and the value is the actual file to upload |
| 44 | + data: files[filesWithPresignedURL.type] |
| 45 | + }; |
| 46 | + |
| 47 | + return $http(S3RequestOptions); |
| 48 | + |
| 49 | + }); |
53 | 50 |
|
54 |
| - return $http(S3RequestOptions) |
| 51 | + return $q.all(promises) |
55 | 52 | .then(function(response) {
|
56 | 53 | console.log('response from S3: ', response);
|
57 | 54 | })
|
|
0 commit comments