0

I have written a VB.Net Visual basic console application for Self hosting a custom file upload service to be consumed by an application. Concept being the end user uses the application to generate data, when completed the file is uploaded to our server without user intervention. I have complete control over both applications. The problem is I can't figure out the POST Upload signature that can accept several params, including the file or how to actually receive the file. The User application is in beta now, testing all other functionality excluding the "Send File" sub's. I've never seen a file larger then 180 KB; I plan on accepting files sizes up to 1 MB. This lets me place some limitations (and filters) to help avoid abuse of the service.

I'm using NuGet packages webapi.client (4.0.30506), webapi.selfhost (4.0.3056) (and their associated required packages) and newtonsoft.json (4.5.11) and PostMan to test/debug the process. I'm using Visual Studio 2019 (Fully patched and up to date). All of the examples and google research point only to C# (not my language of choice), or are for hosted solutions like IIS.

In Postman, the only place where filenames are accepted are in the body, form-data. So, there is where I set up my key/value pairs with matching (including case and order) the params as defined in the FileULRequest class.

Postman Screen Shot

Everything that I've tried returns either

'500 internal server error'

or

"Message": "No HTTP resource was found that matches the request URI 'http://10.0.1.102:21212/file/upload/'."

The class object of the request looks like this:

Public Class FileULRequest
    Public Property EncToken As String  'Holds an encrypted token for authorization
    Public Property Filename As String  'Holds a recommended file name
    Public Property AppID As String     'Holds the client/app ID for simpler server actions
    Public Property File As Byte()      'Not sure if this is the right type/ should be the encrypted file contents.
End Class

The POST function signature currently looks like this:

Imports System.Web.Http

Namespace Controllers
    Public Class FileController
        Inherits ApiController

        Public Function PostUpload(<FromBody()> ByVal ObjRequest As FileULRequest) As String

            Return ""

        End Function

    End Class
End Namespace

In the Sub Main I have: (note, this is cleaned out)

Sub Main()
    API_URL = Dns.GetHostByName(Dns.GetHostName()).AddressList(0).ToString()
    Dim ThisConfig As New HttpSelfHostConfiguration("HTTP://" & API_URL & ":" & API_PORT)
    ThisConfig.Routes.MapHttpRoute(name:="FileUpload", routeTemplate:="{controller}/{ObjRequest}", defaults:=New With {.id = RouteParameter.Optional})
    ThisConfig.MaxConcurrentRequests = API_MaxCon
    Dim Config As HttpSelfHostConfiguration = ThisConfig
    Using Webserver As New HttpSelfHostServer(Config)
        Try
            Webserver.OpenAsync().Wait()                                    'Start the web server
            Console.WriteLine("Listening at: " & API_URL & ":" & API_PORT)  'use the URL & port defined
            Console.WriteLine("Enter to end")
        Catch ex As Exception
            Console.WriteLine("Error:{0}", ex.Message.ToString)
            Console.WriteLine("Enter to end")
            Console.ReadLine()
            End
        End Try
        Dim Cmd As String = UCase(Console.ReadLine())
        End
    End Using
End Sub

API_Port and API_MaxCon are properties stored in the Appsettings.

What I'm trying to do is set the FileULRequest object params, post this to the service, confirm & validate the data and, if successful, save the file onto a network share. I've tried a large number of different combinations and nothing seems to get close; I cant get inside the Post event in the debugger to figure out or test anything.

Fred Kerber
  • 155
  • 3
  • 13
  • Your route is most likely wrong. Figuring out what the actual route is, that's a pita. Might help if you explicitly decorate your class and upload method with RoutePrefix and Route attributes. –  Aug 23 '19 at 15:26
  • I've checked and validated the route and verb; When I change the Postman prams to raw and use application/json, set the properties (excluding file because it's not available here), I get into the Sub PostUpload and get the ObjRequest populated as needed. If I go this route, I'm not sure if a field can contain a meg of data. – Fred Kerber Aug 23 '19 at 16:03
  • Sorry for the back to back comments. So, I can set limits on the POST message body size. Going this process means I'd have to deal with elements in the file contents rather then just grabbing and encrypting a file stream. I was hoping to avoid dealing with the file contents. – Fred Kerber Aug 23 '19 at 16:32
  • Here's a similar question with lots of details, may help. https://stackoverflow.com/questions/24769379/why-is-it-that-no-http-resource-was-found-that-matches-the-request-uri-here –  Aug 23 '19 at 16:47
  • I forgot this was sitting here; It was 2 items; routing being the biggest issue and how I was assembling the command. User1228 recommendation got me back on track. Thank you to all who commented and helped. – Fred Kerber Jul 24 '20 at 17:31

0 Answers0