You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi! I'm trying to POST against a REST endpoint that uploads a file as part of a FormData object. From what I can tell, apollo-link-rest transforms FormData objects into {} prior to sending.
There's a few issues somewhat similar (like this) but the resolutions don't seem to work for me.
// FileList/File are only available in some browser contexts
// Notably: *not available* in react-native.
if (
((global as any).FileList && object instanceof FileList) ||
((global as any).File && object instanceof File) ||
object instanceof FormData) // <----- new line
) {
// Object is a FileList or File object => no keys to convert!
return object;
}
import UPLOAD_DOCUMENT from './updateDocument.gql';
...
const [uploadDocument] = useMutation(UPLOAD_DOCUMENT);
const payload = new FormData();
payload.append('file', file, file.name);
uploadDocument({
variables: {
payload,
// we need the transform function to again prevent `body` from turning into a `{}`
transform: (body: FormData, headers: Headers) => ({
body,
headers,
}),
},
});
Then things appear to work fine. But I'm not sure if I'm missing something key here - there doesn't seem to be much documentation around file uploads (I notice you ask in the other issue for help providing documentation - I'd be happy to if I understood what to do!)
The text was updated successfully, but these errors were encountered:
We added FileList/File support in #164 v0.7.2 and there's more additions for ArrayBuffer/Blob support, so this is probably similar to those issues.
I've mostly used apollo-link-rest in react-native which doesn't support FormData/File objects so I don't have much experience with how painful this is!
Feel free to open a PR if you figure out how to fix it!
Hi! I'm trying to
POST
against a REST endpoint that uploads a file as part of aFormData
object. From what I can tell,apollo-link-rest
transformsFormData
objects into{}
prior to sending.There's a few issues somewhat similar (like this) but the resolutions don't seem to work for me.
From what I can tell, this particular bit destroys an incoming
FormData
object and returns a blank object ({}
). If I change line 615 like so:With the following gql:
And the following JS:
Then things appear to work fine. But I'm not sure if I'm missing something key here - there doesn't seem to be much documentation around file uploads (I notice you ask in the other issue for help providing documentation - I'd be happy to if I understood what to do!)
The text was updated successfully, but these errors were encountered: