In my project we need to save the image taken from webcam in a default path using flex 4.6 but giving a default path in flex(saving the image in a default path like C:\temp..) is not possible so we are passing the byte array of that captured image from flex to .ashx page in .net here,image is saving in a default path but imagebytes is not saving(showing that no data in image).If any body knows please let me know.
Finally i got the succeeded in passing the imagebytes from flex to ashx page like below
//Declare a string in script tag(Initialize a string before init() )
[Bindable]public var str64enc:String="";
//creating object for bytearray
[Bindable]public var imgbytes:ByteArray=new ByteArray();
//creating object for bitmapdata
[Bindable]public var picture1:BitmapData=new BitmapData(103,103,true);
**In your code**
var png:PNGEncoder=new PNGEncoder();
imgbytes=png.encode(picture1);
var base64enc:Base64Encoder=new Base64Encoder();
base64enc.encodeBytes(imgbytes);
str64enc=base64enc.toString();
STEP-BY-STEP PROCEDURE:-------
1-Take a base64encoder and encode the bytearray as below:
var base64enc:Base64Encoder=new Base64Encoder();
base64enc.encodeBytes(imgbytes);
2-then assign that base64 encoder object(In this case" base64enc") to string
3-In HTTPSERVICE u need to pass that string like:
<mx:HTTPService id="savepcktdata" method="POST"
url="ur's destination path like..(axis/security/security.aspx)"
result="savepcktdata_resultHandler(event)"
resultFormat="text">
<mx:request>
<Operation>savepcktdata</Operation>
<bytes>
{str64enc}
</bytes>
</mx:request>
</mx:HTTPService>
4- In .aspx page u need to retrieve like:
string str = Convert.ToString(Request.Form["bytes"]);
cocnclusion:In order to pass the image bytes from flex(flash builder 4.6) to dotnet
(visual studio) you need to pass through the base64 string like above code.
Below is the useful link related to this issue
How to pass image from a flex application to a asp net c# web service? asp-net-c-sharp-web-service
Related
How to upload a Image with RestSharp without using a local path.
Image exists only in a Image Variable.
All i found was with a string as path, but this is not the way i want to go.
Or is it possible to get the string Path from a ImageSource?
How can this be solved?
My current code:
var client = new RestClient();
var request = new RestRequest(PostImageUrl, Method.Post);
request.AddOrUpdateHeader("Content-Type", "multipart/form-data");
request.AddFile("image", bauzeichnung);
request.AlwaysMultipartFormData = true;
var response = client.Execute(request);
It is not possible, every file is need a source. But I can suggest methods that I do not recommend.
You can convert image to base64 string and save image as string
You can take Url of image and show in your app. But in this case image is should be updated to network before(Url).
You can ConvertImage to base64 and store it in your cache.
You can convert Image to ByteArray.
None of these recommendations are correct methods!!!
The most accurate method;
You can take the image and store it in your machine(Local or Server). Then tahe the path of image and save database as Url(If you don't know the difference between url and path, you should research it). When you send image just send the url of your image.
I have a component library that uses JS code to generate an image as a base64 string and the image needs to be transposed to C#. The image size is larger than MaximumReceiveMessageSize.
Can I get the value of the MaximumReceiveMessageSize property in C#? I need a way to correctly split the picture into chunks, or some other way to transfer it.
My component can be used in a Wasm or Server application. I can't change the value of the MaximumReceiveMessageSize property.
Thanks
Using a stream as described in the Stream from JavaScript to .NET solved my problem.
From Microsoft docs:
In JavaScript:
function streamToDotNet() {
return new Uint8Array(10000000);
}
In C# code:
var dataReference = await JS.InvokeAsync<IJSStreamReference>("streamToDotNet");
using var dataReferenceStream = await dataReference.OpenReadStreamAsync(maxAllowedSize: 10_000_000);
var outputPath = Path.Combine(Path.GetTempPath(), "file.txt");
using var outputFileStream = File.OpenWrite(outputPath);
await dataReferenceStream.CopyToAsync(outputFileStream);
In the preceding example: JS is an injected IJSRuntime instance. The dataReferenceStream is written to disk (file.txt) at the current user's temporary folder path (GetTempPath).
I am developing an Android App using Xamarin Studio in order to capture a picture and then send it to a web service.
The steps are:
Capture the picture and store it on the phone.
The web service receives an object as argument. This object contains the image in Base64. This is achieved in the following line:
oImagenFace.ImagenDocumento =(string)Base64ToBitmapDrawableConverter.ConvertBack(BitmapFactory.DecodeFile (imagepath));
At this point I am getting an Out of Memory Exception, but I can not resize the image (as explained here http://developer.android.com/training/displaying-bitmaps/load-bitmap.html) because I need it with the original size. The images are about 200Kb.
Did you tried to skip the BitmapFactory.DecodeFile, and convert the whole file into Base64?
Sg. like this:
oImagenFace.ImagenDocumento =(string)Base64ToBitmapDrawableConverter.ConvertBack(imagepath);
If that won't help, I would try to read the file by chunks and convert that parts to Base64.
Upload Image on Web Server using Android / C# {Xamarin}
This is Just Small Piece of Code. it can send any image from Android to your Web
Server.
System.Net.WebClient Client = new System.Net.WebClient();
Client.Headers.Add("Content-Type", "binary/octet-stream");
byte[] result = Client.UploadFile("localhost/FolderName/upload.php", "POST", path);
string s = System.Text.Encoding.UTF8.GetString(result, 0, result.Length);
Here is the PHP Code {upload.php}. Create a Folder name { Uploads } in
your Application.
<?php
$uploads_dir = 'uploads/'; //Directory to save the file that comes from client application.
if ($_FILES["file"]["error"] == UPLOAD_ERR_OK)
{
$tmp_name = $_FILES["file"]["tmp_name"];
$name = $_FILES["file"]["name"];
move_uploaded_file($tmp_name, "$uploads_dir/$name");
}
?>
I am a beginner in .net Technology. I am using VS2008, C# ,Asp.Net 3.5 Framework, SQL SERVER 2005. In a database table 'Cust_M_Tbl', there is a field of varchar(500) type viz Cust_Image. The value in the Cust_Image is
mspZVnmQlz1GgRRpQEqBFGTHeUELiUhxQQ2GQU9BF3DCUYEeaiJJAQQLKGCBDYcySMENDi9qgQWJv0xBEe8sWkEEDr19QQWMxVoBE20odAEGFDtZAQeBtUtBDn7NUkEd0ytIAQl/r4WBBooWTAEHiCSGAQiMyjEBCFG+KYELYSoowQzluisBBt1NTwEYSM4hgQ5LTTpBD0e5KUEGYa0ugQxqoCLBCWgZKcEKcJJZQQ2DM1nBBAszVoEHiQMSZGhtcwEGCgwPExQUExMUFAMSYmVqcHUECQsOEBMTEhITFAISZWVobnUDCA0PERMVFRQUFRUDEWBjaG5yAQYLDg8REREREQISamlqb3UFCQ0PEhMUFRUWFhYDEV9hZmxxdQMJDQ4PEBEREQIRa2xucXcGCg0PEhMVFhgZGQQRY2ZpbXIBBgsNDxASExQDEHJzdgMHDA0PEBMVFxgZBBFiY2ZpbnMDCQsNDxIVFwMPc3YDBgkNDQ4PExQWGAQRXl9hY2ZqcwQIDBATFxgEDgQHCgwPDQ8PEhMVAxFXWFlcXV9hbXYFCxIWGRoGDA0ODwsODxMDEFVXV1dVVltkcwYOFhodAAD/Aw1PUVFQTk5RV2YKEQAA/wQMR0VFR0ZJQz0xAAD/BQdCQkMY8B0ZtKlQFCF/MssEMp7YkXe5scQP8fmd96ZVrvO8oGFXhoDAjEe5o+U/XAnxKOTp9vDgoSTOH22Eg2rytkcs9uqvFV7GSeUaetGWD0jVWeSqCuD6Sb6l/KxsWXbH1iDoY8LJhgKhkvVBei3Xmp4gx74bl58QiXckdX0KgxJhDWSa/zDvZvGfSVKVLvXzhv8/A+3tV1M36hSdkpPukozfqJj4O9ELUHNNUj8SRvFr0do7bU6tXqEbVubYYiVnalpHbCb07QoVPsO402Lwu3d9vnk6+bnZ/zbgpmAm4zfCLQrlOseeQ4XOarfqeCA14qS2EWZxATfilss++PYY+xymdxgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGA==
I want to display this customer image in my web page. How can I do it? Should I decrypt it? or it is in any other format? Any help will be appreciated. Regards,
After decoding as #Christophe Geers suggested
use
string encodedString = "your image data encoded as base 64 char array";
byte[] data = Convert.FromBase64String(encodedString);
Response.BinaryWrite(data);
maybe this can help more:
http://odetocode.com/articles/172.aspx
This looks like Base64 encoding. You can find an online decoder here:
http://en.wikipedia.org/wiki/Base64
It validates your input as a valid Base-64 char array.
You can decode a base64 string in C# in the following way:
string encodedString = "your image data encoded as base 64 char array";
byte[] data = Convert.FromBase64String(encodedString);
Take a look at the FromBase64String article on MSDN for more information.
Now you want to display the image on an ASP.NET web page (*.ASPX).
E.g.:
<img src="myimage.jpg" />
Instead of referencing an actual image file (eg: myimage.jpg), you want to reference an ASP.NET handler (*.ASHX) that serves the bytes of the image (the byte[] array named data in the previous code sample).
E.g.:
<img src="ImageHandler.ashx" />
The code for the image handler looks something like this:
public class ImageHandler : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
// Load the image (see previous code sample)
byte[] data = ...;
// Display the image
context.Response.OutputStream.Write(data, 0, data.Length);
context.Response.ContentType = "image/JPEG";
}
}
Read more about implementing an IHttpHandler on MSDN.
You need to pass an identifier to the imagehandler.ashx page so that you know which image to retrieved.
E.g.:
<img src="ImageHandler.ashx?id=<%=id%>" />
Put this instead of your img-tag or your ASP.NET image control.
I have a byte[] that contains all the data that represents an image. How do I serve it out as an actual Image in a browser ? The following code returns just a list of bytes:-
List<HubAsset> hubAsset = _core.GetHubAssets(query);
byte[] file = Convert.FromBase64String(hubAsset[0].Data);
return file;
This has been on SO already:
Streaming byte[] to Image in ASP.NET C#