How to upload an image with additional data?

RBeaubien

Member
Licensed User
Longtime User
I need to upload images to a web site, along with additional information such as Title, etc...

I'm using the HttpUtils, and the application is crashing..

I am reading the file in, convert it to Base64, and doing a PostString.

Here is the code I am using to read the image in, and convert it to Base64.

B4X:
   inStream = File.OpenInput(photoPath, cur.GetString("PhotoFilename"))

   Dim buff(inStream.BytesAvailable) As Byte
   
   inStream.ReadBytes(buff, 0, inStream.BytesAvailable)
   
   tempVal = su.EncodeBase64(buff)

however, as soon as that is complete, and it tries to execute the next line of code, the application gets an error "The application <name> (Process <name>) has stopped unexpectedly. Please try again".

Two questions...

1) Is that code correct for converting the file to Base64 string?

2) Is there a better way to upload a file with additional data?

Thanks!
 

RBeaubien

Member
Licensed User
Longtime User
Ok, figured out what I was doing wrong with the input stream.

Should have gotten the size of the file and not used the BytesAvailable as the two won't necessarily match.
 
Upvote 0

RBeaubien

Member
Licensed User
Longtime User
Ok, I'm now having an issue with the Base64 Encoding.

I encode it with the String Utilities, send it to the web site, however, in VB.NET, when I try to decode it, it tells me that it has an invalid length for a Base64 char array.

Any ideas?
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…