locked
Http Post With multipart/form-data parameters RRS feed

  • Question

  • I Want To upload The Files to Online API Which Accepts The Files With Other String Parameters which is Similar to Following python Script..where

    The file part of the call should contain the name of the submitted file and the file itself.

    host = "www.urladdress.com"
    selector = "https://www.urladdress.com/api/v2/file/upload"
    fields = [("apikey", "1fe0ef5feca2f84eb450bc3617f839e317b2a686af4d651a9bada77a522201b0")]
    file_to_send = open("test.txt", "rb").read()
    files = [("file", "test.txt", file_to_send)]
    json = postfile.post_multipart(host, selector, fields, files)

    i am picking the Files With FilesPicker in Windows8 App

    now i want to uload the picked files to API with Above MEntioned parameters..

    My Code Snippet To Pick The File as Follows upon Clicking the Button

    ---------------------------------------------------------------------------------------------

     async private void Button_Click_1(object sender, RoutedEventArgs e)
            {
                FileOpenPicker openPicker = new FileOpenPicker();
                openPicker.ViewMode = PickerViewMode.Thumbnail;
                openPicker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary;
                openPicker.FileTypeFilter.Add("*");
                IReadOnlyList<StorageFile> files = await openPicker.PickMultipleFilesAsync();
                if (files.Count > 0)
                {
                    StringBuilder output = new StringBuilder("Picked files:\n");
                    // Application now has read/write access to the picked file(s)
                    foreach (StorageFile file in files)
                    {
                        output.Append(file.Name + "\n");
                    }


                    textbox1.Text = output.ToString();

                }

    }

    Sunday, August 11, 2013 5:51 PM

All replies

  • I advise you to check out the HttpClient sample code:
    http://code.msdn.microsoft.com/windowsapps/HttpClient-sample-0c4d3c6c

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Monday, August 12, 2013 1:05 PM
    Moderator
  • when i Tried The HTTP Client Sample..But Since it Uses Highly Structured Approach i couldn't Succeed After Copying Some Code segments from it...



    I have Attached The Solution File Here for Refernce Please Look int it..
    http://jabir.in/samples/sample.zip

    It Should Pick The File From Filepicker and Should Upload The File to API as Multipart form through Post Method


    But What i Got the Best Solution After Googling is this
    http://www.briangrinstead.com/blog/multipart-form-post-in-c

    But After Copying the above class into My Xaml page it gives Error for Follwing Propertys and methods

    Useragent for the Instance of Type HttpWebRequest (Line no 57 on file ItemDetailPage.xaml.cs in Attached Solution)
    ContentLengt for the Instance of Type HttpWebRequest (Line no 59 on file ItemDetailPage.xaml.cs in Attached Solution)
    GetRequestStream() for the Instance of Type HttpWebRequest (Line no 67 on file ItemDetailPage.xaml.cs in Attached Solution)
    Close() for the Instance of Type requestStream (Line no 70 on file ItemDetailPage.xaml.cs in Attached Solution)
    GetResponse()  or the Instance of Type HttpWebRequest (Line no 73 on file ItemDetailPage.xaml.cs in Attached Solution)
    Close() for the Instance of Type memorystream (Line no 124 on file ItemDetailPage.xaml.cs in Attached Solution)

    What i am Really Trying to do is This (Sending and scanning files section)
    https://www.virustotal.com/en/documentation/public-api/

    Waiting for the Help..Thnx in Advance...


    • Edited by Jabeer Yusuf Thursday, August 15, 2013 4:40 AM Link Change
    Thursday, August 15, 2013 4:39 AM