forwardemail / forwardemail/superagent

Using superagent as a writable stream

Open
#1,250 9 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
16.6k
Forks
1.3k
PR merge metrics
No merged PRs in 30d

Description

Hi there,

I am trying to upload some files to [OpenStack ObjectStorage](https://developer.openstack.org/api-ref/object-storage/index.html?expanded=create-or-replace-object-detail#create-or-replace-object), creating a read stream from a file and piping into request.

```js
var request = require('superagent');

var req = request.post(base);
var stream = fs.createReadStream('/path/to/file');

req.on('response', function(res) {
console.log('Success');
});

stream.pipe(req);
```

The above works for text files, but for images nothing happens and the request times out.

**Update:** I added listeners for the `'error'` event on both readable and writable streams but there is nothing

Using `.attach()` "works" but the uploaded file now has all the multipart form metadata i.e. the image is "corrupted".

### Versions
Node v4.8.3
Superagent 3.5.2

Any ideas? I feel like I am missing something obvious here, thanks in advance 😄

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.