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.

How to pass `stream.file` to another server as `multipart/form-data`?

See original GitHub issue

Hi there!

I’ve started to use apollo-upload-server and faced with an issue. What I want to achieve is to pass (proxy) stream.file to another server as a file (multipart/form-data). Any ideas how I can do that without saving files.stream to the file and then streaming that file to another server?

I’ve posted similar question here

Issue Analytics

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

github_iconTop GitHub Comments

3reactions
igat64commented, Aug 3, 2018

This is my current workaround/hack

...
    const tmpFilePath = `${this.config.tmpDirPath}/${uuidv4()}`;
    await new Promise((resolve, reject) => {
      const handlerError = (error) => {
        fs.unlinkSync(tmpFilePath);
        reject(error);
      };
      file.stream
        .on('error', handlerError)
        .pipe(fs.createWriteStream(tmpFilePath))
        .on('error', handlerError)
        .on('finish', resolve);
    });

    const response = await request.post({
      uri: `${this.config.nlpApiBase}/upload`,
      formData: {
        datasheet: fs.createReadStream(tmpFilePath),
      },
      json: true,
    });

    fs.unlink(
      tmpFilePath,
      err => err && console.log('Failed to delete temporary file', err),
    );
...
2reactions
igat64commented, Aug 3, 2018

Yeah, I’m pretty sure that there is nothing wrong with apollo-upload-server. Just posted a question here as nobody responds to me there.

Thank you for the answers and your time. You have made a great tool, thank you for that.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to upload file to server with HTTP POST multipart/form ...
Basic implementation using MultipartFormDataContent :- HttpClient httpClient = new HttpClient(); MultipartFormDataContent form = new ...
Read more >
How to upload file to server with HTTP POST multipart/form-data
GetFileAsync(DBNAME); byte[] fileBytes = null; using (var stream = await file.OpenReadAsync()) { fileBytes = new byte[stream.
Read more >
Upload Any File Using HTTP Post Multipart Form Data
You can achieve that through the following code. Here are the steps to be followed. Step 1. Create a new application in .NET,...
Read more >
Node.js Sending Multipart/form-data from server side(backend)
Form data is a library to create readable "multipart/form-data" streams. Can be used to submit forms and file uploads to other web applications....
Read more >
How to upload multipart/form-data to ASP.NET Core Web API?
How the server stores the uploaded file? Create a Web API 2 project in Visual Studio 2017 or 2019, if you are new...
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