.net api/import gets Error: Unable to read export file key from multipart stream



  • Hi,
    I'm trying to export resources from one jsReports instance to another using the export/import Api
    The Export works firn and I can import the zip file using the jsReports studio or Postman
    I'm experiencing and issue trying to upload from .net using httpClient.

    jsReports version 4.2

    Exception message:
    jsreport-2 | 2024-01-19T13:42:21.077Z - warn: Error during processing request at http://localhost:5489/reporting/api/import?fullImport=true&continueOnFail=false, details: Error: Unable to read export file key from multipart stream
    jsreport-2 | at module.exports (/app/node_modules/@jsreport/jsreport-core/lib/shared/createError.js:10:13)
    jsreport-2 | at MainReporter.createError (/app/node_modules/@jsreport/jsreport-core/lib/shared/reporter.js:49:12)
    jsreport-2 | at /app/node_modules/@jsreport/jsreport-import-export/lib/helpers.js:123:26
    jsreport-2 | at done (/app/node_modules/multer/lib/make-middleware.js:45:7)
    jsreport-2 | at /app/node_modules/multer/lib/make-middleware.js:65:11
    jsreport-2 | at removeUploadedFiles (/app/node_modules/multer/lib/remove-uploaded-files.js:5:28)
    jsreport-2 | at /app/node_modules/multer/lib/make-middleware.js:61:9
    jsreport-2 | at Counter.onceZero (/app/node_modules/multer/lib/counter.js:23:29)
    jsreport-2 | at abortWithError (/app/node_modules/multer/lib/make-middleware.js:56:21)
    jsreport-2 | at Multipart.<anonymous> (/app/node_modules/multer/lib/make-middleware.js:160:41)

    Code Snip:

    var response =await exportClient.PostAsync(_fromUrl + "/api/export", new StringContent(
                    JsonConvert.SerializeObject(request), Encoding.UTF8,
                    "application/json"));
                
                var stream = response.Content.ReadAsStream();
                var streamContent = new StreamContent(stream);
                streamContent.Headers.ContentType = MediaTypeHeaderValue.Parse(MediaTypeNames.Application.Zip);
                var formContent = new MultipartFormDataContent("myDillimeter");
                formContent.Headers.ContentType = MediaTypeHeaderValue.Parse("multipart/form-data");
                formContent.Headers.ContentType.Parameters.Add(new NameValueHeaderValue("boundary","myDillimeter"));
                
                var contentType = formContent.Headers.ContentType.ToString();
                formContent.Headers.Remove("Content-Type");
                var fixedContentType = new string(contentType.Where(x => x != '\"').Select(x => x).ToArray());
                formContent.Headers.TryAddWithoutValidation("Content-Type", fixedContentType);
                
                formContent.Headers.ContentLength = stream.Length;
                formContent.Add(streamContent, "import.jsrexport");
                response = await exportClient.PostAsync(_toUrl + "/api/import?fullImport=true&continueOnFail=false", formContent);
    


  • Here is the change you need to do

    formContent.Add(streamContent, "file", "import.jsrexport");
    


  • Thx.
    Appreciate the prompt response


Log in to reply
 

Looks like your connection to jsreport forum was lost, please wait while we try to reconnect.