I have this code for my drag&drop-function for images. The problem with it is that it saves the file to my computer @"C:\Users\xxxx\Desktop\
temporarily. This is a problem because it means that a user cant use this function. So how can i adjust my code in order to make it work online?
I somehow need to find a way that stores the image temporarily.
public ActionResult SaveUploadedFile(string test)
{
foreach (string fileName in Request.Files)
{
HttpPostedFileBase file = Request.Files[fileName];
var filename = Path.GetFileName(file.FileName);
var sourceimage = System.Drawing.Image.FromStream(file.InputStream);
img = sourceimage;
var dog = new Dog();
byte[] tempImg = dog.imageToByteArray(sourceimage);
var fullPath = @"C:\Users\xxxx\Desktop\" + filename;
file.SaveAs(fullPath);
string link = dog.UploadImage(fullPath);
JObject o = JObject.Parse(link);
string name = (string) o.SelectToken("data.link");
System.IO.File.Delete(@"C:\Users\xxxx\Desktop\" + filename);
var page = RavenSession.Load<DogContentPage>(test);
page.Image = name;
RavenSession.SaveChanges();
}
The method that uploads img to imahehost(dunno if it is relevant):
public string UploadImage(string xOut)
{
using (var w = new WebClient())
{
var values = new NameValueCollection
{
{"image", Convert.ToBase64String(File.ReadAllBytes(xOut))}
};
w.Headers.Add("Authorization", "Client-ID " + ClientId);
var response = w.UploadValues("https://api.imgur.com/3/image", values);
var sr = new StreamReader(new MemoryStream(response));
string result = sr.ReadLine();
return result;
}