From a8c210165938cfa4da7ed6bc185af297d528d2aa Mon Sep 17 00:00:00 2001 From: Ivan Chen Date: Wed, 30 Jun 2021 15:32:52 -0400 Subject: Remove filename requirement for all moment upload --- src/services/MomentService.ts | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) (limited to 'src/services') diff --git a/src/services/MomentService.ts b/src/services/MomentService.ts index b274ef04..ad0b0042 100644 --- a/src/services/MomentService.ts +++ b/src/services/MomentService.ts @@ -6,6 +6,7 @@ import { MOMENT_TAGS_ENDPOINT, MOMENT_THUMBNAIL_ENDPOINT, PRESIGNED_URL_ENDPOINT, + RADIO_BUTTON_GREY, TAGG_CUSTOMER_SUPPORT, } from '../constants'; import { @@ -16,7 +17,6 @@ import {MomentPostType, MomentTagType, PresignedURLResponse} from '../types'; import {checkImageUploadStatus} from '../utils'; export const postMoment = async ( - fileName: string, uri: string, caption: string, category: string, @@ -25,13 +25,9 @@ export const postMoment = async ( try { const request = new FormData(); - //Manipulating filename to end with .jpg instead of .heic - if (fileName.endsWith('.heic') || fileName.endsWith('.HEIC')) { - fileName = fileName.split('.')[0] + '.jpg'; - } request.append('image', { uri: uri, - name: fileName, + name: 'moment.jpg', // we don't care about filename, anything works type: 'image/jpg', }); request.append('moment', category); @@ -219,14 +215,13 @@ export const deleteMomentTag = async (moment_tag_id: string) => { * This function makes a request to the server in order to provide the client with a presigned URL. * This is called first, in order for the client to directly upload a file to S3 * @param value: string | undefined - * @param filename: string | undefined * @returns a PresignedURLResponse object */ -export const handlePresignedURL = async ( - filename: string | undefined, - momentCategory: string, -) => { +export const handlePresignedURL = async (momentCategory: string) => { try { + // TODO: just a random filename for video poc, we should not need to once complete + const randHash = Math.random().toString(36).substring(7); + const filename = `[pc_${randHash}].mov`; const token = await AsyncStorage.getItem('token'); const response = await fetch(PRESIGNED_URL_ENDPOINT, { method: 'POST', @@ -260,13 +255,11 @@ export const handlePresignedURL = async ( /** * This util function takes in the file object and the PresignedURLResponse object, creates form data from the latter, * and makes a post request to the presigned URL, sending the file object inside of the form data. - * @param filename: the filename * @param filePath: the path to the file, including filename * @param urlObj PresignedURLResponse | undefined * @returns responseURL or boolean */ export const handleVideoUpload = async ( - filename: string, filePath: string, urlObj: PresignedURLResponse | undefined, ) => { @@ -297,7 +290,7 @@ export const handleVideoUpload = async ( uri: filePath, // other types such as 'quicktime' 'image' etc exist, and we can programmatically type this, but for now sticking with simple 'video' type: 'video', - name: filename, + name: 'moment.mov', // we don't care about filename, anything works }); const response = await fetch(urlObj.response_url.url, { method: 'POST', -- cgit v1.2.3-70-g09d2 From 7dc3ed67d4008ad4dd171dcae846639d9349c4d4 Mon Sep 17 00:00:00 2001 From: Ivan Chen Date: Wed, 30 Jun 2021 17:25:15 -0400 Subject: Lint --- src/services/MomentService.ts | 1 - 1 file changed, 1 deletion(-) (limited to 'src/services') diff --git a/src/services/MomentService.ts b/src/services/MomentService.ts index ad0b0042..9e853a49 100644 --- a/src/services/MomentService.ts +++ b/src/services/MomentService.ts @@ -6,7 +6,6 @@ import { MOMENT_TAGS_ENDPOINT, MOMENT_THUMBNAIL_ENDPOINT, PRESIGNED_URL_ENDPOINT, - RADIO_BUTTON_GREY, TAGG_CUSTOMER_SUPPORT, } from '../constants'; import { -- cgit v1.2.3-70-g09d2 From 29f64921943fb7016ab0db79e4c06377d617a3bf Mon Sep 17 00:00:00 2001 From: Ivan Chen Date: Thu, 1 Jul 2021 15:53:25 -0400 Subject: Add logic for handling new video upload handshake --- src/screens/profile/CaptionScreen.tsx | 14 +++++++++----- src/services/MomentService.ts | 2 +- 2 files changed, 10 insertions(+), 6 deletions(-) (limited to 'src/services') diff --git a/src/screens/profile/CaptionScreen.tsx b/src/screens/profile/CaptionScreen.tsx index da3efb06..05db8ed7 100644 --- a/src/screens/profile/CaptionScreen.tsx +++ b/src/screens/profile/CaptionScreen.tsx @@ -145,14 +145,18 @@ const CaptionScreen: React.FC = ({route, navigation}) => { let momentId; // separate upload logic for image/video if (isMediaAVideo) { - const presignedURL = await handlePresignedURL(title); - if (!presignedURL) { + const presignedURLResponse = await handlePresignedURL(title); + if (!presignedURLResponse) { handleFailed(); return; } - momentId = presignedURL.moment_id; - // TODO: assume success for now - await handleVideoUpload(mediaUri, presignedURL); + momentId = presignedURLResponse.moment_id; + const fileHash = presignedURLResponse.response_url.fields.key; + if (fileHash !== null && fileHash !== '' && fileHash !== undefined) { + await handleVideoUpload(mediaUri, presignedURLResponse); + } else { + handleFailed(); + } } else { const momentResponse = await postMoment(mediaUri, caption, title, userId); if (!momentResponse) { diff --git a/src/services/MomentService.ts b/src/services/MomentService.ts index 9e853a49..87bdfa40 100644 --- a/src/services/MomentService.ts +++ b/src/services/MomentService.ts @@ -289,7 +289,7 @@ export const handleVideoUpload = async ( uri: filePath, // other types such as 'quicktime' 'image' etc exist, and we can programmatically type this, but for now sticking with simple 'video' type: 'video', - name: 'moment.mov', // we don't care about filename, anything works + name: urlObj.response_url.fields.key, }); const response = await fetch(urlObj.response_url.url, { method: 'POST', -- cgit v1.2.3-70-g09d2 From c08a67f5cc1d622e91828d0557c6716a40ee5bad Mon Sep 17 00:00:00 2001 From: Ivan Chen Date: Thu, 1 Jul 2021 16:23:19 -0400 Subject: Fix filename bug --- src/services/MomentService.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/services') diff --git a/src/services/MomentService.ts b/src/services/MomentService.ts index 87bdfa40..60e6be3f 100644 --- a/src/services/MomentService.ts +++ b/src/services/MomentService.ts @@ -220,7 +220,7 @@ export const handlePresignedURL = async (momentCategory: string) => { try { // TODO: just a random filename for video poc, we should not need to once complete const randHash = Math.random().toString(36).substring(7); - const filename = `[pc_${randHash}].mov`; + const filename = `pc_${randHash}.mov`; const token = await AsyncStorage.getItem('token'); const response = await fetch(PRESIGNED_URL_ENDPOINT, { method: 'POST', -- cgit v1.2.3-70-g09d2