New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uploading image from online link to supabase always returns application/octet-stream #1085
Comments
This looks like a Workers runtime related issue, rather than a Wrangler specific one. |
Hey @leadream, this is indeed an interesting problem and most likely with the Worker Runtime. Now do you have any compatibility date set in your |
@evanderkoogh Yes, I have this in my |
@leadream can you check whether |
@petebacondarwin Sure, it's what I expect. My code is: export async function compressImage(request: Request, env: any, supabase: SupabaseClient): Promise<Response> {
try {
const blob = await fetch('https://tinypng.com/images/panda-happy-2x.png')
.then(response => response.blob())
console.log('blob type', blob.type)
const fileName = 'test.' +blob.type.split('/')[1]
const result = await supabase
.storage
.from('avatars')
.upload(fileName, blob, {
cacheControl: '3600',
contentType: blob.type,
upsert: true,
})
console.log(result)
return handleResponse(result, null)
} catch (error) {
return handleResponse(null, error)
}
} |
I note that you are running this in |
@petebacondarwin I published it and it works well. |
Thanks for that! So I think we can narrow it down to it being a Miniflare issue then.. @petebacondarwin you are probably better placed to make sure it gets on the agenda over there? |
I think we need to raise an issue here https://github.com/cloudflare/miniflare/issues. |
@mrbbot - any ideas here? |
Did some digging, this is the code in // Local
import { FormData } from "undici";
const blob = new Blob(["test"], { type: "text/plain" });
const formData = new FormData();
formData.append("file", blob);
const formDataEdBlob = formData.get("file");
console.log(formDataEdBlob.type); // "" // Workers Runtime (and also Firefox)
const blob = new Blob(["test"], { type: "text/plain" });
const formData = new FormData();
formData.append("file", blob);
const formDataEdBlob = formData.get("file");
console.log(formDataEdBlob.type); // "text/plain" See the corresponding A potential temporary solution though is to pass a non- const buffer = await blob.arrayBuffer();
const result = await supabase.storage
.from("avatars")
.upload(fileName, buffer, {
cacheControl: "3600",
contentType: blob.type,
upsert: true,
}); |
When appending a Blob-like or File-like object to FormData, the item is wrapped in a `File` object. But this was causing any options, such as `type` to be hidden in the wrapped type and not exposed at the top level. This fix copies the approach used in `formdata-polyfill` and so also `node-fetch` where the wrapped object is also passed as the `options` argument when creating a new `File` object. Fixes cloudflare/workers-sdk#1085
Great investigation @mrbbot! And thanks for the workaround. I proposed a fix to the undici project here: nodejs/undici#1467 @mrbbot - does the update to a new version of undici need to be tracked here or in Miniflare? |
I'd say in Miniflare. There's actually an open issue (cloudflare/miniflare#220) to upgrade Miniflare's |
Cool. In that case I am going to close this, since there is nothing to track here and you have provided a workaround. |
When appending a Blob-like or File-like object to FormData, the item is wrapped in a `File` object. But this was causing any options, such as `type` to be hidden in the wrapped type and not exposed at the top level. This fix copies the approach used in `formdata-polyfill` and so also `node-fetch` where the wrapped object is also passed as the `options` argument when creating a new `File` object. Fixes cloudflare/workers-sdk#1085
When appending a Blob-like or File-like object to FormData, the item is wrapped in a `File` object. But this was causing any options, such as `type` to be hidden in the wrapped type and not exposed at the top level. This fix copies the approach used in `formdata-polyfill` and so also `node-fetch` where the wrapped object is also passed as the `options` argument when creating a new `File` object. Fixes cloudflare/workers-sdk#1085
When appending a Blob-like or File-like object to FormData, the item is wrapped in a `File` object. But this was causing any options, such as `type` to be hidden in the wrapped type and not exposed at the top level. This fix copies the approach used in `formdata-polyfill` and so also `node-fetch` where the wrapped object is also passed as the `options` argument when creating a new `File` object. Fixes cloudflare/workers-sdk#1085
When appending a Blob-like or File-like object to FormData, the item is wrapped in a `File` object. But this was causing any options, such as `type` to be hidden in the wrapped type and not exposed at the top level. This fix copies the approach used in `formdata-polyfill` and so also `node-fetch` where the wrapped object is also passed as the `options` argument when creating a new `File` object. Fixes cloudflare/workers-sdk#1085
I tried to upload a file from a URL to Supabase storage. I always get an object with
application/octet-stream
mime type. It only happens on Cloudflare workers. I tried it on a normal server and it works well. Here is my code:The text was updated successfully, but these errors were encountered: