-
-
Notifications
You must be signed in to change notification settings - Fork 135
Closed
Description
I am using apollo-upload-server with graphql-nodejs boilerplate template, and apollo-upload-client implementation with react native (expo).
While uploading the files from filesystem, the filesize on the server is at least 5-6 times the size in the local system. I do not know what is the exact cause of the issue. Here are the steps to reproduce:
In Expo, I am returning the local uri from ImagePicker and creating a file to upload:
const picture = new ReactNativeFile({ uri: returnedURI, type: 'image/jpg', name: 'somename.jpg', });
and then running a mutation as follows:
<Mutation mutation={uploadFileMutation}>
{uploadFile => (
<Button
styleName="clear"
style={{ flex: 1 }}
onPress={() => {
uploadFile({
variables: {
picture,
},
});
}}
>
</Button>
)}
</Mutation>
On the server-side, upload is processed as follows:
const processUpload = async upload => {
const { stream, filename } = await upload
const { id, path } = await storeUpload({ stream, filename })
return path
}
const storeUpload = async ({ stream, filename }) => {
const id = nanoid()
const path = somepath
return new Promise((resolve, reject) =>
stream
.pipe(createWriteStream(path))
.on('finish', () => resolve({ id, path }))
.on('error', reject),
)
}
const file = {
async uploadFile(parent, { picture }, ctx, info) {
const resolvedURL = await processUpload(picture)
const url = `http://localhost:4000/${resolvedURL}`
return ctx.db.mutation.createFile(
{
data: {
url,
},
},
info
)
},
}
Here are two images for comparison - one from the filesystem, and second uploaded one
Metadata
Metadata
Assignees
Labels
No labels