How to get image from url using c# / javascript - c#

I am using file picker apis , i can easily upload my files to there server and they give me a unique url in return . When it comes to again fetch that file its creating a problem to me .
You can tell me how to get back file using that url by using filepicker api .
You can tell me how to use that url and get image , by using c#
When i upload a picture to filepicker.io they return me a json object like following
[{"url":"https://www.filepicker.io/api/file/kIrtNvQRta7GxlFVfiP2","filename":"brazil.jpg","mimetype":"image/jpeg","size":2660,"key":"ZML3OjrFTVyV4waBzRIT_brazil.jpg","isWriteable":true}]
So how to get back that image file using c# / Filepicket javascript api
Edit
In my site user will come and upload many photos , and every link to that photo will be stored in database . Now if user want to see his uploaded pictures then i want to fetch them again from server by url . So give your solutions acc. to this scenario .
Thanks in advance

You could put the picture in a PictureBox first using: PictureBox.Load(string);
After the PictureBox is filled with the image from the url, you can decide what to do next like: saving etc.
PictureBox.Load

Related

Add image to https server using local method in web api c#

I am trying to save image to the URL: “https://www.my domain.com”. But while I am trying to save using file stream I am getting a url path along with project location in my local. For ex: “H:/Api/projectname/https://www.my domain.com“.
Anyone please help me how to deal with this.
Thank you in advance.
I want to save image on “https://www.my domain.com” url. No matter what environment is.

How do I create a link to a file I have saved as a memory stream in a SQL table?

My web application (C# and ASP.Net) allows someone to upload a jpg/pdf file and save it as a memory stream inside a SQL table. This is what it looks like once written in the table:
0xFFD8FFE000104A4649.....
Now I want to provide this file back on my web interface through a link where the user can download this file. I have retrieved my file by converting the string above back to a byte array using
filedata = Encoding.ASCII.GetBytes(<string above>);
Then I called this:
string filename = "pic.jpg";
File.WriteAllBytes(filename, filedata);
But I have no clue how I should post this back to the user as a downloadable link on my web interface. Do I have to save this file to a temporary folder on my server or is there a way that I could invoke a call to render my file back as a picture where the user will be prompted to save the file or open it?
Thank you!
You will need to create a page / action / function that writes the bits back as the response to an HTTP request. Keep in mind that in doing so you will probably need to set the proper Content-Type header in the response according to what your file is.
So, you generate a link that calls your page / action / function. Then That sends the binary data back in an HTTP response. Something like
pic.jpg
If you some detail as to what framework you're using (MVC, WebForms, etc) then we can give more detailed examples.
Depending on how you want to present the image.
If you want to embed the image in the web return an link to the file with
string filename = Path.Combine(HttpRuntime.AppDomainAppPath, "Content/Images/pic.jpg");
File.WriteAllBytes(filename, filedata);
return filename;
then in the JavaScript side create an img element with thatsrc
Or if you want the user to download the file do what #squillman says in his answer

File Upload(Image and Video) using Akamai's NetStorage CMS API in C#

I am trying to use the Akamai's NetStorage CMS API for uploading images and videos using asp.net fileupload and looking for any C# REST API(Controller) where we can call NetStorage Upload method.
Looked in their documentation and googled for AKamai CMS API file upload C#, but returned with no luck.
I know how to upload a txt file using Akamai upload method and write content to that text file, but i am looking for something like:
User selects a file
Use that file and upload to Akamai file storage
And when user edits that image(example to rename image title or author info) , get the image from Akamai storage.
Any help would be greatly appreciated.
Thank you so much in advance.
There is a NetStorageKit for C# here:
https://github.com/akamai-open/NetStorageKit-C-Sharp

Download attached file from Facebook using C# API

I able to download an image from facebook conversations using FB API but now i had a problem to download an attached file (.doc, .txt, .log and etc.) from facebook using graph FB API.
Json result return by Facebook if have attached file as below:
"message":"test sent attachment","attachments":{"data":[{"id":"10203275664207489","mime_type":"application/octet-stream","name":"service.log","size":432}]}},
Which is dont have any URL link to the file. But for image that json return by facebook contain url for the that picture. See Json below:
"message":"Gambaq","attachments":{"data":[{"id":"10203185045102068","mime_type":"image/jpeg","name":"10391434_10203185044782060_6466381862586755357_n.jpg","size":null,"image_data":{"width":720,"height":960,"is_sticker":false,"url":"https://fbcdn-sphotos-h-a.akamaihd.net/hphotos-ak-xpt1/v/t34.0-12/11304104_10203185045102068_881196838_n.jpg?
I use this API code for getting Json result:
dynamic resultsByApi = fb.Get("/" + fbFanPage + "/conversations?access_token=" + tokenPage + "");
My question here is anybody know how to get attached file URL for facebook conversations using FB API?
Can anybody please help me to solve this issues. Thank you in advanced.
To use the REST method to get the attachment data, it's
https://api.facebook.com/method/messaging.getattachment
With expected parameters are:
access_token=YOUR_ACCESS_TOKEN
mid=MESSAGE_ID
aid=ATTACHMENT_ID
format=json //(it defaults to XML otherwise)
{"content_type":"image\/png","filename":"jagadeesh.png ","file_size":14587,"data":<contents of data>}
its working v2.0 is expected..
also look at this fql details

Get real type of file that user want to upload

in my ASP.Net MVC 3 application I have uploading images logic. How can I find out is some file that user try to upload realy an image? I need to check it before uploading , on client side
If you use:
Image.FromStream(stream)
it will throw an ArgumentException if it is not a valid image.

Categories