asp.net mvc - Download functionality MVC 4 -
i have created web api connects users dropbox via oauth. using api interact dropbox, works locally like, when deploy api azure server, unable download. had anticipated happen, api hard codded path on machine. here method using: note: i call method through actionresult, part of mvc portion of project
public filesysteminfo downloadfile(string root, string path) { var uri = new uri(new uri(dropboxrestapi.apicontentserver), string.format("files?root={0}&path={1}", root, uppercaseurlencode(path))); var oauth = new oauth(); var requesturi = oauth.signrequest(uri, _consumerkey, _consumersecret, _accesstoken); var request = (httpwebrequest) webrequest.create(requesturi); request.method = webrequestmethods.http.get; var response = request.getresponse(); var metadata = response.headers["x-dropbox-metadata"]; var file = parsejson<filesysteminfo>(metadata); using (stream responsestream = response.getresponsestream()) using (memorystream memorystream = new memorystream()) { byte[] buffer = new byte[1024]; int bytesread; { bytesread = responsestream.read(buffer, 0, buffer.length); memorystream.write(buffer, 0, bytesread); } while (bytesread > 0); file.data = memorystream.toarray(); } return file; }
this call method in action result.
var file = api.downloadfile("dropbox", "public/downloadthis.jpg"); path = file.path; file.save(@"....\desktop\demotest\downloads\downloadthis.jpg"); --- problem & *save* stream writer
is there procedure follow when downloading files server on browser?
public actionresult download(models.downloadmodel dowld, models.loggerview log) {
string tc_id = request.querystring["id"].tostring(); string filename = tc_id+"_loggerdata" + ".zip"; response.contenttype = "application/octet-stream"; response.appendheader("content-disposition", "attachment;filename=" + filename); response.transmitfile(server.mappath("~/files/" + filename)); response.end();
}
Comments
Post a Comment