Upload image using nativescript-background-http to asp.net web service


#1

Struggling to get this working.

var filename = appSettings.getString("filename");
              var session = bghttp.session("image-upload");
              var options = {
                  url: "https://webservice_url/service.asmx/SaveFiles",
                  method: "POST",
                  headers: {
                      "Content-Type": "application/octet-stream",
                      "File-Name": loginId+".jpg"
                  },
                  description: "{'Uploading': 'Uploading File....'}"
              }
              let task = session.uploadFile("file://"+imgPath,options);
              task.on("progress", logEvent);
              task.on("error", logEvent);
              task.on("complete", logEvent);
              function logEvent(e){
                  console.log(e.eventName);
              }

And my asp.net file

Public Function SaveFiles() As String
        Dim newfileparam() As String
        'Dim newpathparam() As String
        'Dim Rotation() As String
        ' Try
        'writefile("Function called")
        Dim FileCount As Integer = 0
            FileCount = HttpContext.Current.Request.Files.Count
            writefile("FileCount = " + FileCount.ToString)
            For i As Integer = 0 To FileCount - 1
                myfile = HttpContext.Current.Request.Files(i)
                FileName = HttpContext.Current.Request.Files(i).FileName
                writefile("FileName = " + FileName)
                If FileName.EndsWith(".jpg") Then
                    FileName += ".jpg"
                End If
                If FileName.EndsWith(".mov") Then
                    FileName += ".mov"
                End If
                If FileName.EndsWith(".mp4") Then
                    FileName += ".mp4"
                End If
                Dim parameters As NameValueCollection = HttpContext.Current.Request.Params
                newfileparam = parameters.GetValues("newfile")
                writefile("newfileparam length: " + newfileparam.Length.ToString)
                newfilename += newfileparam(0).ToString
            Next
            writefile("Newfilename=" + newfilename)
            newfileloc = Path.Combine("d:\images", newfilename)
            writefile("File uploaded: " + newfileloc)
            myfile.SaveAs(newfileloc)
            Return "success"
        'Catch ex As Exception
        '    writefile("****Error: " + ex.Message.ToString + "****")
        '    Return "fail"
        'End Try
    End Function

Nothing appears to be passed to the asp.net webservice from the native script function.

Any thoughts please.


#2

The issue possibly could be anywhere, may be on server side or may be some with ISS config. It’s hard to track just by looking at a code snippet and honestly I never worked with ASP.Net.

So I would suggest you to first try the demo app (mobile + node server) in the plugin repo, make sure it works for you locally (it should). Then try to point the demo app to your ASP.Net server at least that will make it clear which side actually has the problem then it may be easy for you to debug.