Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6670815
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:18:49+00:00 2026-05-26T03:18:49+00:00

Trying to upload a form with a file input, only getting the form fields

  • 0

Trying to upload a form with a file input, only getting the form fields from the input stream and not the File.Request method.

The form contains a file input and a couple of text boxes so I cant just upload the stream to the database.

I convert to string using this method

    int len = Convert.ToInt32(context.Request.InputStream.Length);
    byte[] stream = new byte[len];
    context.Request.InputStream.Read(stream, 0, len);
    string mime = Encoding.UTF8.GetString(stream);

and then split the multipart/form-data at the boundaries and read the first line of each part to see if its a file or not. You can see the full code Here

A file will look something like this

-----------------------------17901701330412 
Content-Disposition: form-data; name="file"; filename="IMG00004-20101209-1704.jpg" 
Content-Type: image/jpeg 

�����ExifII* ����(1�2�i��Research In MotionBlackBerry 9105HHRim Exif Version1.00a2010:12:09 17:03:59 ��n�0220�v���� � ��� �2010:12:09 17:03:59���    $ &&$ #"(-:1(+6+"#2D36;=@A@'0GLF?K:?@>  >)#)>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>��!������ }!1AQa"q2���#B��R��$3br� %&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz������������������������������������������������������������������������� w!1AQaq"2�B���� #3R�br� $4�%�&'()*56789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz�������������������������������������������������������������������������� ?�`��ⳓ5��f)¤b��a�BS�Sb�)Xz�֝�q�"s�K�PA���}F7&��Vm��GӬ��%]� Uҵ�Z7��h�`�@&i ��i��MKB�P��r���-�B|ϛ=3Yٶ ��

and a field will look something like this

-----------------------------17901701330412 
Content-Disposition: form-data; name="parent" 

clientphotos

Parsing the field is easy, and getting the image content is easy, but then saving that in to the database so i can read it back out as an image, isnt so easy.

I have tried byte[] data = Encoding.UTF8.GetBytes(rawdata); but the output isnt correct.

Has anyone any ideas how to take the image content and save it to a byte[] as it should be?


UPDATE

The first line is from getting the image from context.Request.Files[name].InputStream.Read(data, 0, fs);

The second line is using Encoding.UTF8.GetBytes(rawdata);

The third line is using Encoding.ASCII.GetBytes(rawdata);

Obviously the first line is correct and works.

SQL Result

For now Im just using the first line to get the result and it’ll probably stay that way unless someone can teach me how to read it from the input stream.


UPDATE

Found a nice place to share the code Source Code The trouble is on line 49 which for now just reads the Request.Files

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T03:18:49+00:00Added an answer on May 26, 2026 at 3:18 am

    You shouldn’t store the image as text, store in its raw binary form. If you HAVE to store binary data as text you will need to encode it with Base64, but its going to be alot bigger than it needs to be.

    http://www.vbforums.com/showthread.php?t=287324

    byte[] encData_byte = new byte[data.Length];
    encData_byte = System.Text.Encoding.UTF8.GetBytes(data);    
    string encodedData = Convert.ToBase64String(encData_byte);
    return encodedData;
    

    You will also need to do the reverse to get it back into a usable image format. A much better solution would be to store the binary image in a blob/binary field type in the database.

    EDITED: Just reread your post and I see your data is already in base64, just store than in the database?

    EDITED AGAIN: The Initial Question has been edited a number of times, I believe I answered the question but now the question has changed through a number of iterations and my initial answer is now less applicable.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to extend a form and add an upload file field from within
I'm trying to implement this method of making a nice form upload: www.kavoir.com/2009/02/styling-file-upload-select-input-control-input-typefile.html/ which
I was trying to make a file upload form and checked the PHP documentation
I'm trying to upload a file to the server using a HTTP multipart form
I am trying to upload a file or stream of data to our web
I am trying to find out how to upload a file from a web
I'm trying to use resteasy 2.0.1.GA to upload a form with a file in
I'm trying to use the JQuery Form plugin (http://jquery.malsup.com/form/) to upload a file and
I am trying to implement a file upload to a pre-existing form that I
I am trying to fake a file upload without actually using a file input

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.