Uploading File using Windows.Web.Http.HttpClient - WinRT 8.1 PCL - windows-phone-8.1

I have a requirement of uploadng the file to Server in Win8.1 PCL project.
Windows.Web.Http.HttpClient.
I tried in Advanced Rest Client and it works fine
PFA # http://i.stack.imgur.com/N8cv5.png
I have the Code like this.
Windows.Web.Http.HttpRequestMessage request = new Windows.Web.Http.HttpRequestMessage(Windows.Web.Http.HttpMethod.Post, uri);
HttpStreamContent streamContent = new HttpStreamContent(stream.AsInputStream());
streamContent.Headers.Add("Content-Type", "multipart/form-data; boundary=" + boundary);
streamContent.Headers.Add("Content-Length", stream.Length.ToString());
streamContent.Headers.Add("Content-Disposition", "form-data; name=\"" + flKey + "\"; filename=\"" + fleNm + "\"");
request.Content = streamContent;
var httpClient = new Windows.Web.Http.HttpClient();
var cts = new CancellationTokenSource();
Windows.Web.Http.HttpResponseMessage response = await httpClient.SendRequestAsync(request).AsTask(cts.Token);
String resp = response.Content.ToString();
This is not working. Pls le me know whats wrong with the Code, why this code is not able to write the file to the server.
Thanks in Advance

Related

Xamarin get webservice with parameter

i am new with xamarin. I want to add some json data with get web service. I try like following:
var response = await client.GetAsync("myurl" + "?applicationid=" +
applicationId + "?siteid=" + siteId + "?userid=" + userId");
string responseJson = await response.Content.ReadAsStringAsync();
Debug.WriteLine("response:>" + responseJson);
But code not executed after get method.
please anyone help me.
Thanks in advance. :)
Finally got the solution, pass the values with the url itself.
var response = await client.GetAsync("mybaseurl"+"/applicationid/"1"/siteid/"5"/u‌​serid/"+25");

FileStream - Path found in console-application but not in mvc

Iv'e used this guide drive quickstart and successfully got it worked in a console-app.
Now I'm trying to do the same thing in an mvc-application, but I got error when creating a new FileStream.
The code a use is exactly the same in mvc instead this time i'ts triggered by a button-click. This is my code:
using (var stream = new FileStream("client_secret.json", FileMode.Open, FileAccess.Read))
{
string credPath = System.Environment.GetFolderPath(
System.Environment.SpecialFolder.Personal);
credPath = Path.Combine(credPath, ".credentials/drive-dotnet-quickstart.json");
credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
GoogleClientSecrets.Load(stream).Secrets,
Scopes,
"user",
CancellationToken.None,
new FileDataStore(credPath, true)).Result;
Console.WriteLine("Credential file saved to: " + credPath);
}
// Create Drive API service.
var service = new DriveService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = ApplicationName,
});
// Define parameters of request.
FilesResource.ListRequest listRequest = service.Files.List();
listRequest.PageSize = 10;
listRequest.Fields = "nextPageToken, files(id, name)";
// List files.
IList<Google.Apis.Drive.v3.Data.File> files = listRequest.Execute()
.Files;
I got error at 'using (var stream = new FileStream("client_secret.json", FileMode.Open, FileAccess.Read))'
My 'client_secret.json'-file is stored at the root of my mvc project.
And I've done the step: Select client_secret.json, and then go to the Properties window and set the Copy to Output Directory field to Copy always.
Why is this not working in my mvc-app?
The error I get is 'System.IO.FileNotFoundException' - '{"Cannot find file c:\windows\system32\inetsrv\client_secret.json.":"c:\windows\system32\inetsrv\client_secret.json"}'

Adobe AIR file upload response data in complete handler is null while fiddler(web debugger) shows that json is returned as response

When uploading a file from adobe AIR to a backbone server, the response returned is not anyway accessible when using file.upload(request) function, while i can see json response in fiddler(web debugger and in task manager), also it was working fine when using URLLoader.load() instead of file.upload()
var url = "api url of backbone server ";
request = null;
file = null;
request = new air.URLRequest(url);
request.useCache = false;
var authorization = new air.URLRequestHeader("Authorization", "Bearer "+accessToken);
var contentType = new air.URLRequestHeader("Content-Type", "multipart/form-data; boundary=" + boundary);
var Accept = new air.URLRequestHeader("Accept", "application/json;charset=UTF-8");
request.requestHeaders.push(authorization);
request.requestHeaders.push(contentType);
request.requestHeaders.push(Accept);
file = new air.File(path);
pathNative = file.nativePath;
var directory = getDirectoryFromPath(pathNative);
params = new air.URLVariables();
params.parent_id = directory.directory_id;
params.name = file.name;
request.data = params;
request.method = air.URLRequestMethod.POST;
request.contentType = 'multipart/form-data, boundary='+boundary;
var file = new air.File(path);
file.upload(request);
file.addEventListener(air.Event.COMPLETE, function(e){
air.Introspector.Console.log(file);
air.Introspector.Console.log(e);
air.Introspector.Console.log(e.target.data);
});
This is the console for complete event as you can see returned data is null.
see console
while in fiddler shows that json is returned.
see fiddler
Seems like it's a known issue on iOS? Are you trying to do this from iOS?
https://forums.adobe.com/thread/1720117?start=0&tstart=0
I ran into the same problem. Instead of using air.Event.COMPLETE, try to use air.DataEvent.UPLOAD_COMPLETE_DATA:
file.addEventListener(air.DataEvent.UPLOAD_COMPLETE_DATA, function(e){
air.Introspector.Console.log(e.data);
});

Using yfrog's uploadAndPost with Actionscript/Adobe AIR

I am trying to upload a photo from an Adobe AIR application to yfrog's api, http://code.google.com/p/imageshackapi/wiki/YFROGuploadAndPost. I have the following code:
public function upload(file:File, msg:String, username:String, password:String):void {
var vars:URLVariables = new URLVariables();
vars["username"] = username;
vars["password"] = password;
vars["public"] = "yes";
vars["key"] = API_KEY; //API_KEY is a constant string that holds my developer key
vars["message"] = msg;
var request:URLRequest = new URLRequest("http://yfrog.com/api/uploadAndPost");
request.method = URLRequestMethod.POST;
request.contentType = "multipart/form-data";
request.data = vars;
file.upload(request, "media");
}
When I run this code, yfrog returns 404 status. This seems to only happen if I do a media file upload with the api. If I use a "url" upload to the same api url - everything works. Has anyone else gotten a "media" file upload to work? If so, how would you change the code?
Looks like that API has been replaced as of today with the OAuth Echo method
http://code.google.com/p/imageshackapi/wiki/TwitterAuthentication

Report Output Export File Name Issue in CRM 4.0

We have recently upgraded our CRM system from 3.0 to 4.0. Since then we are
having troubles with our reports.
Whenever we export the report to excel format, the file which is created in
CRM 4.0 has name as some "GUID".xls. Not just the name of the file, the sheet
contianing the output also has GUID as the name. This applies to other
formats also (output file name contains GUID).
I can save the rename the file as something else. But we have subscriptions
over most of our reports which sends out excel output of the report to a set
of ppl.
Instead of uploading the RDL from CRM 4.0, if i can upload the report to
some other SSRS folder and give a link, it will work. But we dont want to do
it.
Can anyone help me with this?
Thanks
Not sure, but it's possible to try create custom render extention for Excel. Change the Render method from article as it was proposed by this comment with the only difference - use excel format:
public bool Render(Report report,
NameValueCollection reportServerParameters,
NameValueCollection deviceInfo, NameValueCollection clientCapabilities,
EvaluateHeaderFooterExpressions evaluateHeaderFooterExpressions,
CreateAndRegisterStream createAndRegisterStream)
{
string strUri = string.Empty;
strUri +=
"http://localhost/Reports/Reserved.ReportViewerWebControl.axd";
strUri += "?ReportSession=" + reportServerParameters["SessionID"];
// Here you can check the name of report provided to viewer for export.
// If it's incorrect, you may extend method to set the right name.
strUri += "&FileName=" + report.Name;
strUri += "&ControlId=" + Guid.Empty;
strUri += "&Culture=" +
CultureInfo.CurrentCulture.LCID.ToString(
CultureInfo.InvariantCulture);
strUri += "&UICulture=" +
CultureInfo.CurrentUICulture.LCID.ToString(
CultureInfo.InvariantCulture);
strUri += "&ReportStack=1";
strUri += "&OpType=Export";
strUri += "&ContentDisposition=OnlyHtmlInline";
strUri += "&Format=MHTML";
Stream outputStream = null;
StreamWriter streamWriter = null;
try
{
//Output to Excel
outputStream = createAndRegisterStream(report.Name, "xls",
System.Text.Encoding.UTF8,
"application/vnd.ms-excel", true, StreamOper.CreateAndRegister);
streamWriter = new StreamWriter(outputStream);
//Input
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(strUri);
//Credentials
request.Credentials = System.Net.CredentialCache.DefaultCredentials;
//Output
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
//Input
Stream inputStream = response.GetResponseStream();
StreamReader streamReader =
new StreamReader(response.GetResponseStream());
//Read/Write
streamWriter.Write(streamReader.ReadToEnd());
}
finally
{
if (streamWriter != null)
{
streamWriter.Flush();
}
}
return false;
}
You may add this renderer as a new custom extention (you will have to change subscription format then) or replace existing excel extention - see Specifying Rendering Extension Parameters in Configuration Files