0

I'm using the demo-server from nativescript-background-http and have setup a demo app which sends an image captured by the phones camera to the backend.

    sendPicture(filepath) {
        var url = "http://192.168.200.4:8080"; // Demo server, works
        var name = filepath.substr(filepath.lastIndexOf("/") + 1);

        console.log("FILE: " + filepath);

        // upload configuration
        var bghttp = require("nativescript-background-http");
        var session = bghttp.session("image-upload");
        var request = {
            url: url,
            method: "POST",
            headers: {
                "file-name": name,
                "Content-Type": "application/octet-stream"
            },
            description: "Uploading " + name
        };

        var params = [
            {
                name: name,
                filename: filepath,
                mimeType: "image/jpeg"
            }
        ];

        var task = session.multipartUpload(params, request);

        task.on("error", this.errorHandler);
        task.on("responded", this.respondedHandler);
        task.on("complete", this.completeHandler);
    }

The end result of the image has meta data around it which I have to remove so that I can view it in a image previewing program.

---------AndroidUploadService7465829660026
Content-Disposition: form-data; name="NSIMG_20190827_14127.jpg"; filename="NSIMG_20190827_14127.jpg"
Content-Type: image/jpeg

<The picture binary blob>

---------AndroidUploadService7465829660026--

Why is the demo-server putting this meta data in the uploaded file?

map7
  • 5,096
  • 6
  • 65
  • 128
  • I think the example is very basic with http server which is not recommended for production use. You should try express server & fileupload middleware if you are looking for production ready end points. – Manoj Aug 27 '19 at 09:11
  • @Manoj I'm using Rails + Shrine for my production app, but I was wondering why the demo server put this meta data within the uploaded file. It doesn't seem right to me. – map7 Aug 27 '19 at 23:44

0 Answers0