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.

Getting createReadStream is not a function when uploading a file

See original GitHub issue

graphql-yoga: 1.18.2 react-native: 0.60.4 apollo-upload-client: 11.0.0

Hi there, after updating to 1.18 I can no longer upload files. I’m trying to upload a file using react-native and apollo-upload-client. Here’s what the mutation variable looks like on the client:

data: {
    file: new ReactNativeFile({
      uri,
      type: typeForSaving,
      name: 'photo-1.jpeg'
    })
}

And here’s the server code:

Schema:

scalar Upload

type Mutation {
    contentSingleUpload(data: ContentSingleUploadInput!): SingleUploadPayload!
}

input ContentSingleUploadInput {
    file: Upload
}

Resolver:

async contentSingleUpload(parent, args, ctx, info) {
    const fileResult = await processUpload(args.data.file)
}

const processUpload = async upload => {
    const { createReadStream, filename, mimetype, encoding } = await upload

    const stream = createReadStream()
    ...
}

The request fails with createReadStream is not a function and when I try to look at args.data.file I am seeing: image

Thanks in advance.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:3
  • Comments:12

github_iconTop GitHub Comments

5reactions
wortforfilmscommented, Dec 18, 2020

while working on nexus solution was to call file inside file. try { const { file: { filename, mimetype, encoding, createReadStream }, } = file; console.log(“FIle 1”, file); let stream = createReadStream();

4reactions
aarabmedcommented, Sep 5, 2019

@stephensamra remplace createReadStream with just stream and remove the line const stream = createReadStream()

Read more comments on GitHub >

github_iconTop Results From Across the Web

Apollo Uploading Files, createReadStream is not a function
I tried to get this working for several days and getting now where. I do believe that that the client side is function...
Read more >
How To Work with Files Using Streams in Node.js - DigitalOcean
Streams are an efficient way to handle files in Node.js. ... The createReadStream function creates a readable stream that emits events that ...
Read more >
Can't upload a file from node.js to my route, getting empty ...
I am trying to upload a local file using NodeJs (the file is in the same directory as app.js) to my remote Laravel...
Read more >
Tests in NodeJS hangs when doing a streaming client call and ...
It seems that in a test, a streaming client rpc does not play well when an operation like a file read when the...
Read more >
fs.createReadStream is not a function : r/react - Reddit
To upload a file from browser to server, you need to use File API not fs.
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