Skip to content

Instantly share code, notes, and snippets.

@palanisamym14
Created December 6, 2021 05:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save palanisamym14/d845d518036b5cec43d85c5d9682a5a4 to your computer and use it in GitHub Desktop.
Save palanisamym14/d845d518036b5cec43d85c5d9682a5a4 to your computer and use it in GitHub Desktop.
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