Created
February 27, 2020 01:50
-
-
Save nikasulo/15125dcc067c09e501988245baf6cedb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const uploadToAWS = async(auth_token, file, directory) => { | |
const { data } = await API.get("/upload", {params: {filename: file.name, fileType: file.type, directory: directory}, headers: APIHelpers.authorizationHeaders(auth_token)}); | |
const { post_url, get_url } = data; | |
const options = { | |
headers: {"Content-Type": file.type,'acl': 'public-read'}, | |
} | |
await axios.put(post_url, file, options) | |
return get_url; | |
} | |
export const updateProject = (form, auth_token, fileToUpload) => async(dispatch) => { | |
try { | |
if (fileToUpload) { | |
const image_url = await uploadToAWS(auth_token, fileToUpload, APIHelpers.projectImagePath()) | |
form.set("image_url", image_url); | |
} | |
const params = Object.fromEntries(form); | |
await API.put(`/projects/${params.id}`, params, {headers: APIHelpers.authorizationHeaders(auth_token)}) | |
dispatch(flash(`${form.get("title")} was updated successfully`)); | |
dispatch(setProjectToEdit(null)); | |
} catch(error) { | |
dispatch(flash(`Oops! We couldn't update that project, please try again`)); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment