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.

File stream is null

See original GitHub issue

For some reason, my server is returning an empty stream instead of the file.

Here’s the client’s request:

-----------------------------81678640518046430391178682890
Content-Disposition: form-data; name="operations"

{"operationName":null,"variables":{"file":null},"query":"mutation ($file: Upload!) {\n  uploadUserImage(file: $file)\n}\n"}
-----------------------------81678640518046430391178682890
Content-Disposition: form-data; name="map"

{"1":["variables.file"]}
-----------------------------81678640518046430391178682890
Content-Disposition: form-data; name="1"; filename="signature.jpg"
Content-Type: image/jpeg

******** Whole Lot of data ************
-----------------------------81678640518046430391178682890--

On the server

async (parent, { file }) => {  
  const { createReadStream, filename, mimetype, encoding } = await file;
  const stream = createReadStream();

  stream.on("data", data => {
      console.log("DATA**********************");
      console.log(data);      
    });

  stream.on("readable", () => {
      console.log(stream.read());
    });
}

Nothing gets outputted. When I send stream’s data as response it returns as null.

Interestingly, filename, mimetype and encoding all are populated.

I am using apollo-server-express as my server.

Here’s the schema for the method

uploadUserImage(file: Upload!): String

Will really appreciate your help on this. Thanks 😃

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

10reactions
jaydensericcommented, Feb 19, 2019

You should be promisifying and awaiting the file upload like in the example:

https://github.com/jaydenseric/apollo-upload-examples/blob/master/api/resolvers.mjs#L21

Give that a go and see if you still have the issue.

0reactions
hshankar-loopcommented, Nov 5, 2021

Can someone help to solve the same in python using Django? Thanks in advance!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why the variable FileStream writer is null? - Stack Overflow
Setting the parameter, a local variable named writer in the LocalDirectorySettings() method, has no effect on the other local variable, ...
Read more >
Stream.Null Field (System.IO) - Microsoft Learn
Use Null to redirect output to a stream that will not consume any operating system resources. When the methods of Stream that provide...
Read more >
Listening to ItemAdded File Stream is NUll
I'm currently listening to the ItemAdded event using a RER for a DocumentLibrary, this so far works perfectly. However I have an issue...
Read more >
Problem getting data from filestream C# - CodeProject
I'm passing the file path to create file-stream and when I'm trying to fetch the data from the FileStream, the data is null....
Read more >
Demonstrate the use of the Null stream as a bit bucket
Demonstrate the use of the Null stream as a bit bucket : Stream Null « File Stream « C# / C Sharp ·...
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