0xtech
0xtech
Explore posts from servers
CCConvex Community
Created by 0xtech on 4/9/2024 in #support-community
How to get image url after uploaded image ?
yeah it's working thank you
22 replies
CCConvex Community
Created by 0xtech on 4/9/2024 in #support-community
How to get image url after uploaded image ?
how can I define state value as a Storage Id ?
22 replies
CCConvex Community
Created by 0xtech on 4/9/2024 in #support-community
How to get image url after uploaded image ?
so setting storage id on here
22 replies
CCConvex Community
Created by 0xtech on 4/9/2024 in #support-community
How to get image url after uploaded image ?
const handleAvatarUpload = useCallback(async (file: File) => {
try {
setUploadLoading(true);
const postUrl = await generateUploadUrl();
// Step 2: POST the file to the URL
const result = await fetch(postUrl, {
method: "POST",
headers: { "Content-Type": file!.type },
body: file,
});

const { storageId } = await result.json();
setStorageI(storageId);
} catch (error) {
toast("Something went wrong", {
description: "Our support team has been notified",
});
console.error("Failed to update user profile", error);
}
}, []);
const handleAvatarUpload = useCallback(async (file: File) => {
try {
setUploadLoading(true);
const postUrl = await generateUploadUrl();
// Step 2: POST the file to the URL
const result = await fetch(postUrl, {
method: "POST",
headers: { "Content-Type": file!.type },
body: file,
});

const { storageId } = await result.json();
setStorageI(storageId);
} catch (error) {
toast("Something went wrong", {
description: "Our support team has been notified",
});
console.error("Failed to update user profile", error);
}
}, []);
22 replies
CCConvex Community
Created by 0xtech on 4/9/2024 in #support-community
How to get image url after uploaded image ?
so it's getting issue
22 replies
CCConvex Community
Created by 0xtech on 4/9/2024 in #support-community
How to get image url after uploaded image ?
so calling query like it but as you can see storageId is empty string at first
22 replies
CCConvex Community
Created by 0xtech on 4/9/2024 in #support-community
How to get image url after uploaded image ?
const [storageId, setStorageId] = useState('');
const getImageUrl = useMutation(
api.routes.userProfiles.queries.getImageUrl,
{
imageId: storageId
}
);
const [storageId, setStorageId] = useState('');
const getImageUrl = useMutation(
api.routes.userProfiles.queries.getImageUrl,
{
imageId: storageId
}
);
22 replies
CCConvex Community
Created by 0xtech on 4/9/2024 in #support-community
How to get image url after uploaded image ?
so I made query and it's getting storageId as a argument
22 replies
CCConvex Community
Created by 0xtech on 4/9/2024 in #support-community
How to get image url after uploaded image ?
export const getImageUrl = query({
args: { imageId: v.id("_storage") },
handler: async (ctx, args) => {
return await ctx.storage.getUrl(args.imageId);
},
});
export const getImageUrl = query({
args: { imageId: v.id("_storage") },
handler: async (ctx, args) => {
return await ctx.storage.getUrl(args.imageId);
},
});
22 replies
CCConvex Community
Created by 0xtech on 4/9/2024 in #support-community
How to get image url after uploaded image ?
since useQuery is hook I can only call in the component not function
22 replies
CCConvex Community
Created by 0xtech on 4/9/2024 in #support-community
How to get image url after uploaded image ?
but here is issue
22 replies
CCConvex Community
Created by 0xtech on 4/9/2024 in #support-community
How to get image url after uploaded image ?
I tried with useQuery
22 replies
CCConvex Community
Created by 0xtech on 4/9/2024 in #support-community
How to get image url after uploaded image ?
@Michal Srb yeah
22 replies
CCConvex Community
Created by 0xtech on 4/9/2024 in #support-community
How to get image url after uploaded image ?
this is my development convex url
22 replies
CCConvex Community
Created by 0xtech on 4/9/2024 in #support-community
How to get image url after uploaded image ?
22 replies
CCConvex Community
Created by 0xtech on 4/9/2024 in #support-community
How to get image url after uploaded image ?
I tried but it's not working with 404 issue
22 replies
CCConvex Community
Created by 0xtech on 4/9/2024 in #support-community
How to get image url after uploaded image ?
const convexSiteUrl = import.meta.env.VITE_CONVEX_SITE_URL;

function Image({ storageId }: { storageId: string }) {
// e.g. https://happy-animal-123.convex.site/getImage?storageId=456
const getImageUrl = new URL(`${convexSiteUrl}/getImage`);
getImageUrl.searchParams.set("storageId", storageId);

return <img src={getImageUrl.href} height="300px" width="auto" />;
}
const convexSiteUrl = import.meta.env.VITE_CONVEX_SITE_URL;

function Image({ storageId }: { storageId: string }) {
// e.g. https://happy-animal-123.convex.site/getImage?storageId=456
const getImageUrl = new URL(`${convexSiteUrl}/getImage`);
getImageUrl.searchParams.set("storageId", storageId);

return <img src={getImageUrl.href} height="300px" width="auto" />;
}
22 replies