Skip to content
This repository was archived by the owner on Mar 4, 2025. It is now read-only.

Commit 17a6e28

Browse files
author
Nick Litwin
committed
Call s3 upload from presigned url success callback
1 parent e490dcf commit 17a6e28

File tree

1 file changed

+21
-24
lines changed

1 file changed

+21
-24
lines changed

app/services/submissions.service.js

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,41 +17,38 @@
1717

1818
return service;
1919

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)
2422

2523
return api.all('submissions').customPOST(JSON.stringify({param: body}))
2624
.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);
3428
})
3529
.catch(function(err) {
3630
console.log(err);
3731
$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.');
4033
});
41-
42-
// return deferred.promise;
4334
}
4435

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+
});
5350

54-
return $http(S3RequestOptions)
51+
return $q.all(promises)
5552
.then(function(response) {
5653
console.log('response from S3: ', response);
5754
})

0 commit comments

Comments
 (0)