-
-
Notifications
You must be signed in to change notification settings - Fork 99
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
createObject does not set cacheControl #18
Comments
The way I'm getting around this atm is to implement/use caching on your app. I'm using react query. I have something like: export const fetchAvatar: QueryFunction<string | undefined> = async ({ queryKey }) => {
const [_key, path] = queryKey
const { data, error } = await supabaseClient.storage
.from(AVATAR_BUCKET)
.download(path as string)
if(error) {
throw new Error(error.message)
}
if(!data) {
return undefined
}
return URL.createObjectURL(data)
} then I pass the query function to react-query with options (note staleTime). export const UserAvartar:React.FC<UserAvatarProps> = ({ name, path, className }) => {
const { data } = useQuery(
['avatar', path],
fetchAvatar,
{
enabled: !!path,
staleTime: 1000 * 60 * 60, // 1 hour
}
)
return <Avatar className={className} alt={name} src={data} />
} This means that the fetch for an object is cached for an hour (as long as the user doesn't reload the app), so the user won't have to redownload the same image over and over again. |
Checked after updating Supabase to 1.11.3. Still happening. |
Did some digging just now. The issue is because the controller is calling const data = await request.file() This calls this part of fastify-multipart async function getMultipartFile (options) {
const parts = this[kMultipartHandler](options)
let part
while ((part = await parts()) != null) {
if (part.file) {
// part.file.truncated is true when a configured file size limit is reached
if (part.file.truncated && throwFileSizeLimit) {
throw new RequestFileTooLargeError()
}
return part
}
}
} // https://github.com/fastify/fastify-multipart/blob/master/index.js#L185
fastify.decorateRequest('file', getMultipartFile) As you can see, this only loads the first file it sees, never loading field - thus
will never have a value. The solution would be to use |
Thanks for digging into this @horizon0708. Looks like the non file values need to be sent before the file fields as mentioned here and it is the intended behaviour. Fixing in storage-js |
Can you try with supabase-js 1.11.14 James? |
It's working! Thanks for a quick update! Looks like I was completely off the mark with https://github.com/supabase/storage-api/issues/18#issuecomment-843717897😅 |
I thought it might have to do with something with Fastify as well till I realised that it was working with when I sent the request via Postman but not via supabase-js |
Bug report
Describe the bug
TL;DR When I upload an object to storage via storage-js, the API doesn't care about the cache-control value.
At the moment, when you call
upload()
from the Supabase client, it sets the default cache-control field to 3600 (https://github.com/supabase/storage-js/blob/main/src/lib/StorageFileApi.ts#L15). The API should take this field and set that as max-age (https://github.com/supabase/storage-api/blob/master/src/routes/object/createObject.ts#L59). If this value is not present, it is set to no-cache.When I upload an object to a bucket, I can see that cache-control is set in the request (see screenshot below). This should mean that the server should respond with
cache-control
header value set tomax-age=3600
when I request for the object later on.However, when I download the object afterward, the header is set to no-cache.
This is not desirable behavior, as we want to cache as many things as possible for a good user experience (and probably also lessen the load for Supabase too).
To Reproduce
cacheControl
value set.no-cache
header set.Expected behavior
Supabase API sets cache-control headers that we pass in.
Screenshots
If applicable, add screenshots to help explain your problem.
System information
The text was updated successfully, but these errors were encountered: