Created
December 6, 2021 05:55
-
-
Save palanisamym14/d845d518036b5cec43d85c5d9682a5a4 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
const [path, setPath] = useState({}); | |
useEffect(() => { | |
if (file.name) { | |
fetchMyAPI(); | |
} | |
}, [file.name]); | |
async function fetchMyAPI() { | |
const res: any = await getSignedURL(file.name); | |
setPath(res); | |
} | |
import axios from 'axios'; | |
export const getSignedURL = (s3Url: string) => { | |
const pieces = s3Url?.split('/'); | |
const query = { | |
companyName: pieces[pieces.length - 2], | |
key: pieces[pieces.length - 1], | |
}; | |
return new Promise((resolve, reject) => { | |
axios | |
.post( | |
`${process.env.BASE_URL}/graphql`, | |
{ | |
query: `query GetSignedURL($query: GetSignedURLArgs!) { | |
getSignedURL(getSignedURLArgs: $query){ | |
path | |
url | |
} | |
}`, | |
variables: { | |
query, | |
}, | |
}, | |
{ | |
headers: { | |
'Content-Type': 'application/json', | |
}, | |
} | |
) | |
.then(({ data }) => { | |
resolve(data?.data?.getSignedURL || { path: '', url: '' }); | |
}) | |
.catch((error) => { | |
reject(error); | |
}); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment