Upload images from Mobile to Server - xamarin.forms

I'm developing a Xamarin.Forms application for Android and iOS that needs to take photos and upload its to a Server. Then, to take the photos on the client side, I'm using Xam.Plugin.Media.
But, as this plugin saves the photos in Xamarin.Forms.Image format and I need them in the System.Drawing.Image format on the Server side, first I tried to save the photo taken by Xam.Plugin.Media in a Byte array, upload it to the server and then save the Bytes array in System.Drawing.Image format, but do not work.
After, I searched for several days in the Internet how to convert the formats and I didn't find anything useful, either converting on the mobile side using Xamarin or on the Server side using C#.
Can anyone help me in this challenge?
Thanks in advance and sorry for my poor English.
Marcelo Camarate

First of all I would use MediaPicker from Xamarin Essentials rather than the outdated media plugin. Second, the FileResult you get back provides access to a Stream which you can copy to a MemoryStream ahich you can copy to a byte array with MemoryStream.ToArray() which gives you your byte[]. You can see an example on the page I link to of how to get the stream from the photo and the various docs for the other methods to find out what you need.
You can then upload the bytes however you want based on your server API.

Related

Access Device Camera with Blazor

I have a Blazor Web Assembly PWA, how do I open a devices native camera?
I am trying to write a PWA to capture and save pictures.
EDIT
Would like to save captured images as jpeg's to Azure Blob Storage.
You can achieve this with HTML input. You only need to add the attribute capture for opening device camera straight away.
<input type="file" accept="image/*" capture>
You can have a look at the full source code here:
https://github.com/mehmettahameral/Blazor-wasm-pwa-camera
and live demo here:
https://infallible-bohr-56743b.netlify.app/
--
about saving the images: it depends where do you want to save it really. If you can tell me more, I might update the solution.
Hope it helps 🤞
You can follow this tutorial: https://wellsb.com/csharp/aspnet/blazor-webcam-capture to capture camera device, stream the content, process an image.
Then, you can use the Azure Blob Storage client library v12 for .NET to upload your images to your Storage Account.
You can find a Quickstart here: https://learn.microsoft.com/en-us/azure/storage/blobs/storage-quickstart-blobs-dotnet

Display doc file in browser using asp.net

I am developing a job portal using asp.net. I need to build a control to display the uploaded resume on the browser from the server directory. Could any one share the code to do the same. what is the control appropriate to display the content of a doc file?
Thanks in advance.
There is no ASP.NET server control to display a Word document in a web-page. Microsoft removed the Internet Explorer-only ability to show Word documents in the browser with Office 2007, but before then you could have gotten away with doing it in an <iframe> - note that this does require Word to be installed on the browser's computer.
It sounds like you want to convert the Word document into HTML+CSS. I'll stop you right here, because that is a non-trivial operation, even with the significantly-easier-to-process OOXML file formats. There are commercial libraries that can assist you with this, but they cost $lots. (Bing for "Aspose").
There are a few other alternatives:
Print the document, server-side, to a PDF file. This needs a complicated set-up on the server as the Office COM automation libraries should not be used from headless (e.g. server) code; so you'd need to set-up some kind of GUI-session daemon to do this processing.
Accept only the OOXML file formats and extract only plaintext content (this can be done easily enough without much knowledge of OOXML if you already have experience with manipulating XML in-code).
Accept only plaintext or HTML submissions. This is how most "upload your resume" sites work, including Apple's and Microsoft's careers websites.
If you just want to return the Word document to your visitors, then just return the raw bytes of the file using Response.WriteFile, or write directly to the Response's output stream if you're persisting the Word document outside of the filesystem.

Saving recorded Voice in Flex using as3

I am trying save the recorded voice locally in my file system using flex and as3.
I am successful in recording voice and playback again. I am using web application prospective in Flex.
Here I noticed that if I used windowed application, I am successfully saving voice record in my system(using adobe air file system).
Pleas let me know the process of saving recorded file.
You can save VoiceRecord in ByteArray on Flex Side, and send this ByteArray to Server and save there in File or Database
FileReference.save(), but it has to be converted to ByteArray
There is also a open source alchemy c++ plugin someone built for flash that can encode it to an mp3 on the client. Would probably be of great use to you: https://github.com/kikko/Shine-MP3-Encoder-on-AS3-Alchemy

Advanced image editing off the web

I'm building an app in ASP.NET that will store some pictures of objects. The pictures will be uploaded by suppliers and downloaded by subscribers. In between, they will have to be edited before becoming available to subscribers.
The editing involves creating a cropping path tightly around the object in the picture, in which some advanced desktop image software will have to be used I suppose.
My problem is in exchanging pictures between my ASP.NET app and the desktop software in a manner that is easy and transparent for the user.
I've done some thinking and I've come up with:
- Manually downloading and uploading the image (Not much user friendly...)
- An image editing program that can upload to a web service (Haven't found yet...)
- Develop a plug-in for an image editing program (Too advanced...)
I'd appreciate any suggestions you may have, thank you!
It sounds like you need some automation to move files between the web server and a file share. I am assuming that the number of images that need to be processed is pretty large, because if it's not, then the overhead of downloading/re-uploading each would not be that much.
So do the following:
1) Create an API for your web app that lists files that are available, or new files since some date/time, or files that have been marked as "new". The API should probably also allow marking a status on them (so you can tell it when you've finishing pulling something down, and it won't be offered again) if you don't want to trust date/time as an indicator of it being new.
2) Write an app (non-web) that runs on a schedule and uses this API to automatically download files to a shared filesystem area in your local network, and marks them as "downloaded"
The app should also monitor these files (the ones it downloaded & saved to your local share) for changes, and if changed, upload them back to your web app. To do this you may need to keep a database of filenames and modification dates/times.
This shouldn't be too hard to write in whatever language you are using for your web (assume c# or vb). By "API" I just mean, a web page that provides a list in a standardized format (e.g. json) that you can parse with your automation application, and another page that allows posting the file back for re-upload.
I'm assuming that the web server is not your own, or generally, you can't simply have it save the file uploads directly to some area where your image editors can access them. Otherwise you could just do that.
Meanwhile I came out with another possible solution.
I'm thinking of having our own windows app on the editor's computers. This app will be associated with a custom extension. When an editor downloads a file (with this extension) for editing, it will be opened in our application which in turn will open the image in some editor program.
This app will be monitoring the files for changes, and in such case, it will upload these images.
Any thoughts on this?

Flex Write File

I checked in the API, that writing a file is only in Flex Air.
Despite of that, is there still a way in Flex to write a file on the server or on the client machine ?
More concretely, it's because I have a String and I will decode it by mx.utils.Base64Decoder
to a doc. And I need to open it by Word directly on the client side, or write it on the server and return the link to the client for downloading.
Thanks
I'm doing something similar - I have built a custom grid in Flex that contains an additional button on it that allows the user to open the data up in Excel. I've done this by writing a function in PHP on the server which my Flex speaks to. This creates the CSV file on the server and the function passes the link back to the client, which in turn offers the user the chance to open the data up in Excel.
I'm using the Zend technologies to accomplish this - I recommend you take a look; they're extremely good. I used to use Flex Data Services and Java do do this but just recently switched to PHP because development time is cut down drastically as a result.
Hope this helps.
Jamie.
AIR applications run on the users' desktops. They allow you to write to the users' desktops. Nothing stops Flex/AIR applications from communicating to the server, write some files there (using a suitable backend technology) and return a link back to the user.

Resources