We are using Flash to send an image to the servers and upload an image. The way we're trying to do this is by sending the bytes to the server through a parameter and then converting the bytes to an image.
http://i.gyazo.com/fb8225af80ef465b0262d97f63bd54b2.png
In the image the object is sending a few different bits of information. I'm not sure if I am supposed to just receive one bit of information instead of the entire object.
So far I have the post request
string byteArray = Request["bytes"];
Then I am trying to convert it to an image
string file_name = Guid.NewGuid().ToString();
//byte[] imageBytes = Convert.FromBase64String(byteArray);
Derio.App.Model.Helper.ByteArrayToFile(file_name, Derio.App.Model.Helper.GetBytes(byteArray));
My helper method looks like -
public static class Helper
{
public static byte[] GetBytes(string str)
{
byte[] bytes = new byte[str.Length * sizeof(char)];
System.Buffer.BlockCopy(str.ToCharArray(), 0, bytes, 0, bytes.Length);
return bytes;
}
public static string ByteArrayToFile(string _FileName, byte[] _ByteArray)
{
try
{
// Open file for reading
System.IO.FileStream _FileStream =
new System.IO.FileStream(_FileName, System.IO.FileMode.Create,
System.IO.FileAccess.Write);
// Writes a block of bytes to this stream using data from
// a byte array.
_FileStream.Write(_ByteArray, 0, _ByteArray.Length);
// close file stream
_FileStream.Close();
return "true";
}
catch (Exception _Exception)
{
// Error
return "Exception caught in process:" + _Exception.ToString();
}
}
}
We've multiple different methods such as trying to convert it from Base64String to an image.
I can't for the life of me though figure out what I am doing wrong.
What happens when you try this:
string file_name = Guid.NewGuid().ToString();
string byteArray = Request["bytes"];
byte[] imageBytes = Convert.FromBase64String(byteArray);
IO.File.WriteAllBytes(file_name, imageBytes);
Related
I have a very strange issue. I am converting Image to base64string in an asp.net web API hosted in Azure app service and getting the wrong image string.
If I run the code in the local machine I am getting the correct value.
public static string GetImageFromSharePointOnline(string imageUrl)
{
try
{
using (var clientContext = CreateContext(URL))
{
clientContext.ExecutingWebRequest += ExecutingWebRequest;
FileInformation fileInformation = null;
Stream returnStream = new MemoryStream();
int readCount;
var buffer = new byte[8192];
Uri image = new Uri(imageUrl);
try
{
fileInformation = Microsoft.SharePoint.Client.File.OpenBinaryDirect(clientContext, image.AbsolutePath);
while ((readCount = fileInformation.Stream.Read(buffer, 0, buffer.Length)) != 0)
{
returnStream.Write(buffer, 0, readCount);
}
}
catch (Exception ex) { }
returnStream.Seek(0, SeekOrigin.Begin);
return "data:image/" + GetFileExtensionFromUrl(imageUrl) + ";base64," + Convert.ToBase64String(buffer);
// return Convert.ToBase64String(buffer);
}
}
catch (Exception ex) { }
}
Azure web api output:
data:image/jpg;base64,VHdEqK7rHUHQQ0VMQUMN/T0MMGKzMFUEsTYAdpNTJgXxeGxYh+qoll/MSfCD7AOvxrk3738OrTjPyJZGHi5kcUcsCBYkCJtAUgdeq27da89em0/L0vPW/gt8zw0mAwkS74zmwY9Qe411c+31+rm6cvlx47jzly7b7I1F5Htew9g7Seyt79PmZZ05/VwYcPjsGFlKY6NtIJMgDk2N9d37AK49u21/Lq15axZy+Jw893kmiAlc38xPC1/h1+NTXrtqu3LWlfkeKmwcnypPEp1jfsYV26dJtMuTfn81Pi8ZHzYw6hl8R2sLjRSelTrtjW4OeudjNiQwwlimPDudStzGh0PXs7tK4r02v5dk0k/ClzeBiR8a8iQojqy2ZVCnU27K9eXTa7ea8uvOTXwXY495AAuToAK68ubA/h8Xjwgb0WWX8zMAyj2AHT41x9O1vr06tOMnsWjF4DAUUoWDG4vewsBbpavH6r1xFHkvTsE0LS4sYjnUX2Lor+y3QHutXtz7WXFeXTjLMwtCMEV2uREx0EGSiObJVHJloLES1BajSoqwkQorssNTK4SEIpkws4MC+fv/AOGCw9/QH4E3ry67ftenKfuEooq4nWtxRjs7NKDXKYS5HF5MTC942K+xlF1+8VdLim0zAH0/D/04PbWSQ3PeFAA+y5r17Xy8uU8DUUVhuPQak14vVbgjDKrDVWAIPeDrSrA71Xio3GpKR4opBY+xtCPwr14Xy8u0zATh4wcuM+xv6TXR0v7a8Oc/dDLFDpf7q4nYq+o4h/k7gGxLJcnQC7jtrfK/uY6TwWuGVGzI97W2ncBYm5AuOntrp3viufWeTNFFXG6lmEx+cYf8QKHI9hJH7KC/F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AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=
Can anyone help me with this please.
You're initializing a MemoryStream:
Stream returnStream = new MemoryStream();
(should be var returnStream = new MemoryStream();)
as the container for the bytes read from a Stream.
The Image bytes are read from the source Stream using a buffer:
var buffer = new byte[8192];
which is ok for a NetworkStream.
Assuming Uri image = new Uri(imageUrl); represents the same object in both environments, you the read a [buffer] number of bytes (which is the maximum value, the actual bytes read may be less than that) and write the bytes read - the value is stored in the readCount variable - to the MemoryStream:
try
{
fileInformation = Microsoft.SharePoint.Client.File.OpenBinaryDirect(clientContext, image.AbsolutePath);
while ((readCount = fileInformation.Stream.Read(buffer, 0, buffer.Length)) != 0)
{
returnStream.Write(buffer, 0, readCount);
}
}
When the source Stream is read to end, the MemoryStream contains the Image bytes.
At this point, you want to convert the Image bytes to a Base64String.
Of course, you need to convert the content of your MemoryStream, returnStream, not the buffer content, which is only used as a temporary container for the bytes coming from the source Stream. So just change:
Convert.ToBase64String(buffer);
to:
Convert.ToBase64String(returnStream.ToArray());
Setting returnStream.Position = 0 before calling returnStream.ToArray() is not necessary in this context, but it doesn't hurt either.
Side note: those empty catch blocks don't serve you well. Either add logging features or remove.
I am trying to create an API which will save an image at a given location .
Below is my Code for that
Image image = Image.FromFile(#"C:\Users\abc\Desktop\img-logo.jpg");
byte[] bytes = (byte[])(new ImageConverter()).ConvertTo(image, typeof(byte[]));
string str = Convert.ToBase64String(bytes);
Save_Application_Image("12004", str);
and the method in API
public void Save_Application_Image(string staffCode , string bytearray)
{
try
{
byte[] bytes = Convert.FromBase64String(bytearray);
file_path = "~/uploads/" + file_name;
FileStream file = File.Create(HttpContext.Current.Server.MapPath(file_path));
file.Write(bytes, 0, bytes.Length);
file.Close();
}
catch(Exception ex)
{
logger.LogError(ex);
}
finally
{
}
}
This api has to be called from Android Application so I will receive two string parameter.
It is saving the file perfectly but file is not readable. No preview for image file.
What is the right approach for this ?
I'm unsure of how the ImageConverter works, but I've used this before to convert Images to byte[]:
Image image = Image.FromFile(#"C:\Users\abc\Desktop\img-logo.jpg");
using (var stream = new MemoryStream())
{
image.Save(stream);
string savedImage = Convert.ToBase64String(stream.ToArray());
Save_Application_Image("12004", str);
}
I am getting an exception when trying to convert a base64 string to a byte array. I am converting an Image to a byte array then to a base64 string, then encrypting it and storing it in a file. Then I am attempting to convert the base64 string back to a byte array in a MemoryStream, and recreating the image. I am getting a FormatException here:
byte[] imgBytes = Convert.FromBase64String(str);
Here is the full code for the two main functions:
public string ImageToString(Image img)
{
using (MemoryStream ms = new MemoryStream())
{
img.Save(ms, ImageFormat.Jpeg);
return Convert.ToBase64String(ms.ToArray());
}
}
public Image StringToImage(String str)
{
int lent = str.Length;
byte[] imgBytes = Convert.FromBase64String(str);
MemoryStream ms = new MemoryStream(imgBytes, 0, imgBytes.Length);
ms.Write(imgBytes, 0, imgBytes.Length);
return Image.FromStream(ms, true);
}
Here is the beginning and end of the base64 string I am trying to convert....
G>/9j/4AAQSkZJRgABAQEAYABgAAD .... Uh+8fxpT/B9KAP/2Q==
Any ideas are greatly appreciated!
The problem is that your string got corrupted somewhere along the line. That's not a base64 string, as you can see by the second charcter >, which does not occur in a base64 string.
Side note: Your function creates a memory stream containing the data, then writes the data to the memory stream again. Then you try to read from the memory stream without resetting the position to the beginning of the stream.
Just create the memory stream and read from it:
public Image StringToImage(String str) {
byte[] imgBytes = Convert.FromBase64String(str);
return Image.FromStream(new MemoryStream(imgBytes), true);
}
I am able to do data transfer between PC and android via bluetooth. But now i want to send image files of size around 80KB. When i send the image, only a part of it gets transfered but not
completely. Does anyone know how to achieve that? I am using TCP and working in C# platform.
string fileName = "send.png";
string filePath = #"C:\Users\Asus 53s\Desktop\"; //path
byte[] fileNameByte = Encoding.ASCII.GetBytes(fileName);
byte[] fileData = File.ReadAllBytes(filePath + fileName);
byte[] clientData = new byte[4 + fileNameByte.Length + fileData.Length];
byte[] fileNameLen = BitConverter.GetBytes(fileNameByte.Length);
fileNameLen.CopyTo(clientData,0);
fileNameByte.CopyTo(clientData,4);
fileData.CopyTo(clientData,4+fileNameByte.Length);
sendMessage(clientData);
}
public Boolean sendMessage(byte[] msg)
{
{
if (!msg.Equals(""))
{
UTF8Encoding encoder = new UTF8Encoding();
NetworkStream stream = me.GetStream();
stream.Write(encoder.GetBytes(msg + "\n"), 0, (msg).Length);
stream.Flush();
}
}
Converting a binary object first to a string and then converting it to UTF-8 is not a good idea... Lots of bad things may happen in the conversions. (And there's also a bug in sendMessage.)
Why not just do:
public Boolean sendMessage(byte[] msg)
{
stream.Write(msg, 0, msg.Length);
stream.Flush();
}
If you really need that final "\n", then add before the Flush:
stream.WriteByte((byte)'\n');
Whilst we're on the subject of UTF-8, why are you presuming that the filename will only contain ASCII characters?? Change that code to:
byte[] fileNameByte = Encoding.UTF8.GetBytes(fileName);
I want to send a binary file to .net c# component in the following xml format
<BinaryFileString fileType='pdf'>
<!--binary file data string here-->
</BinaryFileString>
In the called component I will use the above xml string and convert the binary string received within the BinaryFileString tag, into a file as specified by the filetype='' attribute. The file type could be doc/pdf/xls/rtf
I have the code in the calling application to get out the bytes from the file to be sent. How do I prepare it to be sent with xml tags wrapped around it? I want the application to send out a string to the component and not a byte stream. This is because there is no way I can decipher the file type [pdf/doc/xls] just by looking at the byte stream. Hence the xml string with the filetype attribute. Any ideas on this?
method for extracting Bytes below
FileStream fs = new FileStream(_filePath, FileMode.Open, FileAccess.Read);
using (Stream input = fs)
{
byte[] buffer = new byte[8192];
int bytesRead;
while ((bytesRead = input.Read(buffer, 0, buffer.Length)) > 0)
{}
}
return buffer;
Thanks.
Edit:
Just to clarify why I am using an xml string rather than setting properties on my component. Actually my calling app is trying to simulate how Siebel will call my component.
http://download.oracle.com/docs/cd/E05553_01/books/eScript/eScript_JSReference244.html#wp1014380
Im not sure if Siebel can set my components properties as I need it to. So Im working on the angle of it sending the data in xml.
Base64 representation is universaly used to represent binary data.
public void EncodeWithString() {
System.IO.FileStream inFile;
byte[] binaryData;
try {
inFile = new System.IO.FileStream(inputFileName,
System.IO.FileMode.Open,
System.IO.FileAccess.Read);
binaryData = new Byte[inFile.Length];
long bytesRead = inFile.Read(binaryData, 0,
(int)inFile.Length);
inFile.Close();
}
catch (System.Exception exp) {
// Error creating stream or reading from it.
System.Console.WriteLine("{0}", exp.Message);
return;
}
// Convert the binary input into Base64 UUEncoded output.
string base64String;
try {
base64String =
System.Convert.ToBase64String(binaryData,
0,
binaryData.Length);
}
catch (System.ArgumentNullException) {
System.Console.WriteLine("Binary data array is null.");
return;
}
// Write the UUEncoded version to the XML file.
System.IO.StreamWriter outFile;
try {
outFile = new System.IO.StreamWriter(outputFileName,
false,
System.Text.Encoding.ASCII);
outFile.Write("<BinaryFileString fileType='pdf'>");
outFile.Write(base64String);
outFile.Write("</BinaryFileString>");
outFile.Close();
}
catch (System.Exception exp) {
// Error creating stream or writing to it.
System.Console.WriteLine("{0}", exp.Message);
}
}
At the receiving end you can reverse this and get back original file content as mentioned below.
// Convert the Base64 UUEncoded input into binary output.
byte[] binaryData;
try {
binaryData =
System.Convert.FromBase64String(base64String);
}
catch (System.ArgumentNullException) {
System.Console.WriteLine("Base 64 string is null.");
return;
}
catch (System.FormatException) {
System.Console.WriteLine("Base 64 string length is not " +
"4 or is not an even multiple of 4." );
return;
}
Can you BASE64 your bytes? MSDN ref: Convert.ToBase64, Convert.FromBase64String
expanding on #russau's answer it will work like this:
var s = "Hello World";
var b = Encoding.Default.GetBytes(s);
var bstr = Convert.ToBase64String(b);
Console.WriteLine("Original String:" + s);
Console.WriteLine("Base64 String:" + bstr);
var fromBStr = Convert.FromBase64String(bstr);
var st = Encoding.Default.GetString(fromBStr);
Console.WriteLine("Converted string: " + st);
you wont need first two lines:
var s = "Hello World";
var b = Encoding.Default.GetBytes(s);
as you already have a byte array. I've used string to show that you get exactly the same value you started with in the end when you convert byte array from Convert.FromBase64String
You mention that you are calling a C# component. I'm not sure I understand why using this component means you need to create an XML string.
Is it possible to define classes to hold your data instead of using an XML string? e.g.
public enum FileType
{
Word,
Excel,
RichText,
PDF
}
public class FileData
{
public FileType TypeOfFile
{
get;
set;
}
public byte[] Data
{
get;
set;
}
}
Then the caller of the component just sets the FileType and the byte[]. The component's interface would then be more explicitly defined (FileData class as opposed to the more generic string or XmlDocument).