Send/Receive image or XML file via KSOAP - ksoap2

it may sounds stupid but i would like to know whether is it possible send and receive. maybe image/XML file vai kSOAP?

I have been able to transmit WebRowSet XML documents using kSOAP2.
http://roderickbarnes.com/blog/droid-chronicles-web-services-handling-complex-parameters
In this example I am sending an XML document from the web service to my Android based client. I hope this helps bro.

It is possible to send image via ksoap by following steps:
convert the Image into byte[]
add byte[] of the image as property
register SoapSerializationEnvelope with MarshalBase64() like this : new MarshalBase64().register(envelope);
call your web service which takes byte[] as parameter
Then receiving the message you can convert the receieved byte[] into image file.

Related

Programmable Chat Media Filename (JS)

The Media Support docs it mentions that when sending media you can: "Optionally specify a default download filename to help your application display the media to other users.". This is done using messagingOptions in Swift however in JS I cannot find any supporting documentation on how this is done. Currently, I am sending media as follows:
channel.sendMessage({
contentType: 'image/png',
media: fs.readFileSync(media)
});
I have tried adding a filename with file, filename and name properties without any luck. As you can see the filename is empty in the Twilio console:
Any help on adding a filename is much appreciated, thanks.
The answer:
const data = new FormData();
data.append('file', blob, filename);
According to the FormData docs, you can add a filename as an option like so:
After converting the image to a Base64 string I created a blob from the binary and appended the blob to the form data as shown above. Here is my code:

How to get the shared file with Microsoft Graph?

I want to share files from MS OneDrive to a user via MS graph API. And user can view my shared file directly through the link. I have read the Document of Creating a sharing Link for a DriveItem and use this API to create a sharing link for my sharing files.
I wonder how to implement with MS graph API? Any suggestion and tips are welcome. Thanks
According to your description, I assume you want to get the share file by using MS Graph API.
Base on my test, We can create a shareLink for this this file.
Then we can use the following steps to get the file information by converting the shareLink.
Encoding the shareLink by using the following logic:
1)First, use base64 encode the URL.
2)Convert the base64 encoded result to unpadded base64url format by removing = characters from the end of the value, replacing / with _ and + with -.)
3)Append u! to be beginning of the string.
If you want access the shared files, you can use the following API:
GET /shares/{shareIdOrUrl}/driveItem
The shareIdOrUrl parameter is the result in step1.
This API will return all the information about the shared file.
As an example, to encode a URL in C#:
string sharingUrl = "https://onedrive.live.com/redir?resid=1231244193912!12&authKey=1201919!12921!1";
string base64Value = System.Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(sharingUrl));
string encodedUrl = "u!" + base64Value.TrimEnd('=').Replace('/','_').Replace('+','-');
For more detail, we can refer to this document.

Azure blob authorization header

I am trying to use refit to upload to azure blob storage from a Xamarin iOS application. This is the interface configuration I am using for Refit:
[Headers("x-ms-blob-type: BlockBlob")]
[Put("/{fileName}")]
Task<bool> UploadAsync([Body]byte[] content, string sasTokenKey,
[Header("Content-Type")] string contentType);
Where the sasTokenKey parameter looks like this:
"/content-default/1635839001660743375-66f93195-e923-4c8b-a3f1-5f3f9ba9dd32.jpeg?sv=2015-04-05&sr=b&sig=Up26vDxQikFqo%2FDQjRB08YtmK418rZfKx1IHbYKAjIE%3D&se=2015-11-23T18:59:26Z&sp=w"
This is how I am using Refit to call the azure blob server:
var myRefitApi = RestService.For<IMyRefitAPI>("https://myaccount.blob.core.windows.net");
myRefitApi.UploadAsync(photoBytes, sasTokenKey, "image/jpeg"
However I am getting the follow error:
Response status code does not indicate success: 403 (Server failed to
authenticate the request. Make sure the value of Authorization header is
formed correctly including the signature.)
The SAS url is working fine if I call it directly like this
var content = new StreamContent(stream);
content.Headers.Add("Content-Type", "jpeg");
content.Headers.Add("x-ms-blob-type", "BlockBlob");
var task = HttpClient.PutAsync(new Uri(sasTokenUrl), content);
task.Wait();
So basically I am just trying to do the same thing using Refit.
Any idea how to get Refit working with Azure Blob Storage?
Thanks!
[UPDATE] I am now able to upload the bytes to the azure blob server but something seems to be wrong with the byte data because I am not able to view the image. Here is the code I am using to convert to byte array.
byte[] bytes;
using (var ms = new MemoryStream())
{
stream.Position = 0;
stream.CopyTo(ms);
ms.Position = 0;
bytes = ms.ToArray();
}
[UPDATE] Got it fixed by using stream instead of byte array!
I see %2F and %3D and I'm curious if refit is encoding those a second time. Try sending the token without encoding it.
This is incorrect use of Authorization header. You use Authorization header when you want to authorize the requests using account key. If you have the Shared Access Signature then you really don't need this header as the authorization information is included in the SAS itself. You can simply use the SAS URL for uploading files.

ASP.NET Web API, unexpected end of MIME multi-part stream when uploading from Flex FileReference

Following the tutorial found on ASP.NET, implemented a Web API controller method for doing asynchronous file uploads that looks like this:
public Task<HttpResponseMessage> PostFormData()
{
// Check if the request contains multipart/form-data.
if (!Request.Content.IsMimeMultipartContent())
{
throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
}
string root = HttpContext.Current.Server.MapPath("~/App_Data");
var provider = new MultipartFormDataStreamProvider(root);
// Read the form data and return an async task.
var task = Request.Content.ReadAsMultipartAsync(provider).
ContinueWith<HttpResponseMessage>(t =>
{
if (t.IsFaulted || t.IsCanceled)
{
Request.CreateErrorResponse(HttpStatusCode.InternalServerError, t.Exception);
}
return Request.CreateResponse(HttpStatusCode.OK);
});
return task;
}
Uploading a file via a standard multipart HTML form works perfectly. However, when another developer attempts to upload a file via multipart form constructed by Flex's FileReference class, an error is thrown:
Unexpected end of MIME multipart stream. MIME multipart message is not complete.
I have no idea if the problem lies in Web API or Flex. I've found some sort of related fixes that had no affect (Multipart form POST using ASP.Net Web API), and more recently this one ("MIME multipart stream. MIME multipart message is not complete" error on webapi upload). If the second link holds true, does anyone know if it's out in the current release of Web API available via Nuget? The discussion was in May, the most recent release from Nuget was August, so I assume this fix was deployed already, and is not the root cause of my issue.
I had the same problem with MVC4, but Will is correct, add a name to your input.....
<input type="file" id="fileInput" name="fileInput"/>
and all the magic is back up and working!
I had the same problem with flex. And below is the code that solved it. Basically I used a custom stream to append the newline that asp.net web api is expecting.
Stream reqStream = Request.Content.ReadAsStreamAsync().Result;
MemoryStream tempStream = new MemoryStream();
reqStream.CopyTo(tempStream);
tempStream.Seek(0, SeekOrigin.End);
StreamWriter writer = new StreamWriter(tempStream);
writer.WriteLine();
writer.Flush();
tempStream.Position = 0;
StreamContent streamContent = new StreamContent(tempStream);
foreach(var header in Request.Content.Headers)
{
streamContent.Headers.Add(header.Key, header.Value);
}
// Read the form data and return an async task.
await streamContent.ReadAsMultipartAsync(provider);
Hope this helps.
Reading through your existing research and following through to the codeplex issue reported it looks like someone else confirmed this issue to still exist in September.
They believe that MVC 4 fails to parse uploads without a terminating "\r\n".
The issue is really simple but extremely hard to fix. The problem is that Uploadify does > not add an "\r\n" at the end of the MultiPartForm message
http://aspnetwebstack.codeplex.com/discussions/354215
It may be worth checking that the Flex upload adds the "\r\n"
For those landing here googling:
Unexpected end of MIME multipart stream. MIME multipart message is not complete.
Reading the request stream more than once will also cause this exception. I struggled with it for hours until I found a source explaining that the request stream only could be read once.
In my case, I combined trying to read the request stream using a MultipartMemoryStreamProvider and at the same time letting ASP.NET do some magic for me by specifying parameters (coming from the request body) for my api method.
Make sure the virtual directory ("~/App_Data" directory as below example) where the image files are first uploaded are physically existance. When you publish the project, it may not be in the output files.
string root = HttpContext.Current.Server.MapPath("~/App_Data");
var provider = new MultipartFormDataStreamProvider(root);
I just removed my headers I was setting on my post method which ended up solving this issue.
The problem is this line:
string root = HttpContext.Current.Server.MapPath("~/App_Data");
It will only work in localhost, you can use HostingEnvironment.MapPath instead in any context where System.Web objects like HttpContext.Current are not available (e.g also from a static method).
var mappedPath = System.Web.Hosting.HostingEnvironment.MapPath("~/SomePath");
See also What is the difference between Server.MapPath and HostingEnvironment.MapPath?
Reference to this answer How to do a Server Map Path.

Problem attaching file programmatically to blackberry Email Client

I am attempting to attach an excel spreadsheet to an email programmatically, and then launch the default blackberry email client with the message as an argument. Unfortunately, I receive the error: "Email service does not support these types of attachments. Change the Send Using field or remove the attachments." The send button is not present, and there is no "Send" option in the menu; this is blocking the ability to send the email.
This error occurs when I load the package onto my physical blackberry phone, as well as in the simulator.
I am able to send the email without a hitch if I use the API instead (the commented transport.send line).
Any and all input would be greatly appreciated, and if I've overlooked some details please let me know.
public Email()
{
try{
message = new Message();
multipart = new Multipart(); //Multi part can hold attachment AND body (and more)
subject = "Service Change Request";
multipart.addBodyPart( new TextBodyPart( multipart, "Hi XXXXXX, \n Here are the details for CLIENT" ) );
byte[] data = null;
InputStream stream = MyAPP.getUiApplication().getClass().getResourceAsStream("/blank_form.xls");
data = IOUtilities.streamToBytes(stream);
stream.close();
multipart.addBodyPart( new SupportedAttachmentPart( multipart, "application/octet-stream", "ServiceUpdate.xls", data ) );
Address recipients[] = new Address[1];
recipients[0]= new Address("*******#gmail.com", "user");
message.setSubject(subject);
message.setContent( multipart );
message.addRecipients(Message.RecipientType.TO, recipients);
//Transport.send(message);
}catch(Exception e){
}
}
public void send(){
Invoke.invokeApplication( Invoke.APP_TYPE_MESSAGES, new MessageArguments( message ) );
}
EDIT:
The error comes up because the simulator has no email account configured. It should work just fine on any phone that has an email account properly configured.
I hope this helps and I am not too late to lend a hand on this post.
I've worked with attachments before, and they are a pain to work with in Blckberry.
The only issue I can think of is the MIME type you are trying to use.
"Application/octet-stream", try using the MIME corresponding to the extension of the attachment, for example "application/excel" for .xls files. You can find the complete list here , its the longest one I could find.
There are also some issues with the Blackberry email service and attachments that are mentioned on several Knowledge Base Articles on the official Developers page like this one, they sometimes say that the attachments have to be prefixed with "x-rimdevice" in the file name, like "x-rimdevice-serviceupdate.xls". Although I'm not really sure this affects on outgoing email, but I thought it was worth mentioning.
By the way, I'm trying to use your code for an App I'm coding right now, so I'm kind of hoping it works.

Resources