stefanwalther/qrs

Retrieving binary failed because of 'request' encoding option

Closed this issue · 7 comments

the request lib fails to encode binary properly until you mention : encoding=null
It is needed to export application for instance.

Thx, what's about a PR? ;-)
Or at least some hint, where you fixed it, thx.

@aalteirac: Can you post a code example?

Here's a sample upload, the binary is wrong if the encoding is not set to 'null' :requestOptions.encoding=null;

this.requestUpload = function (fp, method, endpoint, urlParams, body ) {

    var defer = Q.defer();
    var validConfig = _validateConfig();
    if ( !validConfig ) {
        defer.reject( {error: {errorMsg: 'Invalid configuration', errSource: 'qrs.request'}} );
    } else {
        var url = this.getUrl( S( endpoint ).chompLeft( '/' ), urlParams );
        var headers = _getHeaders();
        var certSet=_getPFXFromWStore();
        var requestOptions = {
            method: method || 'GET',
            url: url,
            headers: headers,
            proxy: that.config.fiddler ? 'http://127.0.0.1:8888' : null,
            json: body,
            pfx:certSet.pfx,
            passphrase:certSet.passphrase,
            rejectUnauthorized: false
        };
        requestOptions.encoding=null;
        var req=request.post( requestOptions, function ( error, response, responseBody ) {
            defer.resolve( responseBody );

        })
        var form = req.form();
        form.append('file', fs.createReadStream(fp));


    }
    return defer.promise;
};

OK; thx, will fix.

Hi @aalteirac , do you have the full example, I assume you wanted to upload a media or an extension?

here's the request using it, it's an app upload:
function upload(fp,name){ var p=new promise(function(resolve, reject) { qrs.requestUpload(fp,'POST','app/upload',[{'key':'name','value':name},{'key':'keepdata','value':'true'}],null).then(function(ret){ resolve("OK") }); }) return p; }