question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Streamed file size is 5-6 times bigger than the original size

See original GitHub issue

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

From filesystem- Size: 45kb 81fceb8e-2352-40cd-a10a-c77084fd8a08 Uploaded copy - Size: 257kb iyvmzwjig0coq4bnunbqh

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:10 (2 by maintainers)

github_iconTop GitHub Comments

5reactions
riccardonuclearecommented, May 7, 2021

Hi, We are experiencing a similar issue when uploading an image JPG with iOS with apollo-upload-client. The image is taken from the gallery (original size is around 2.4 MB) and we compress it to around 500 kB. We upload it to server with a mutation where we use graphql-upload with middleware graphqlUploadExpress using ReactNativeFile. However, when we check the image on S3, the image is 2 MB. We tried with several images and the result is similar: uploaded image is bigger than the compressed one. We tried to upload the image without the middleware using a plain POST request and in this case, the image was uploaded with the expected size (500 kB). Interesting that we do not have the same problem with Android using the same code. Any suggestion for debugging it? @mike-marcacci

0reactions
mike-marcaccicommented, Sep 6, 2019

Hmm, are the final uploaded images corrupt? This tool obviously doesn’t do any image transformation, so if the resulting upload is correctly formatted it’s simply uploading the bytes it’s being sent. Using your same server, try uploading an image with a GraphQL client that supports uploads (like altair). If you see the same behavior there, than this is something we should investigate further; otherwise, though, something in the OS or Expo are simply sending a different (less compressed, etc) set of bytes than you are expecting.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Determine streaming video file sizes - IU KB - Indiana University
Determine streaming video file sizes ; 28.8 Kbps modem, 20, 150 ; 56 Kbps modem, 42, 315 ; 128 Kbps ISDN, 100, 750...
Read more >
Understanding file sizes | GreenNet
Every file on a computer uses a certain amount of resources when sent over the internet or stored. Keeping mind of your kilobytes...
Read more >
Audio File Size Calculator - Colin Crawley
Calculates the size of audio files (both uncompressed, PCM/IEEE FP audio, such as “.WAV”, “.W64” “.AIFF/.AIF” and also compressed files such as MP3,...
Read more >
java - When streaming a file from a server, the file size on disk ...
The file size according to artifactory is 34,952,058 bytes, the totalBytes counter that's logged after reading is finished is also 34,952,058 ...
Read more >
Exported file sizes larger than imported originals
Exported file sizes larger than imported originals. Hi there,. I'm having an issue with the file size of a project, when I import...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found