Loading and saving JSON files in a GWT web application - ajax

We are developing an GWT web-application with an Python webapp2 webserver. At this point we want to load and save files within the web-application. We cannot use Flash for this task.
Saving
The current approach is to use a form upload using the target "_blank" and set the correct MIME to make the browser download the file. This solution works, but since the webapp2 webserver does not support streaming (thus the mime type cannot be validated by the browser in a short time), a new browser-window is opened each time. Is there a better solution e.g. using iFrames?
Loading
Again using form upload and parsing the response (JSON). We use the content-type "text/html; charset=UTF-8". This solution works perfectly in IE9 but does not work in Chrome and FireFox. It seems, that the JSON response gets corrupted in some way or is there anything from when parsing a JSON response from a form upload response? We use piriti for JSON (de)serialization.

For loading, you can use RestyGWT library, it has capability encoding or decoding Java Object to JSON:
import javax.ws.rs.POST;
...
public interface PizzaOrderCodec extends JsonEncoderDecoder<PizzaOrder> {
}
// GWT will implement the interface for you
PizzaOrderCodec codec = GWT.create(PizzaOrderCodec.class);
// Encoding an object to json
PizzaOrder order = ...
JSONValue json = codec.encode(order);
// decoding an object to from json
PizzaOrder other = codec.decode(json);
For saving, if you have to send JSON file using file upload, you can see following link:
http://www.jroller.com/hasant/entry/fileupload_with_gwt
http://www.celinio.net/techblog/?p=1207
Have a nice time.

Related

How do I access BlockBlobClient in Azure Storage JavaScript client library for browsers?

I'm attempting to use BlockBlobClient in a browser page to upload a file using a server-supplied sastoken / URL, similar to this C# code:
var blob = new CloudBlockBlob(new Uri(assetUploadUrl));
blob.UploadFromFile(FilePath, null, new BlobRequestOptions {RetryPolicy = new ExponentialRetry()});
Although the docs suggest BlockBlobClient is available in #azure/storage-blob and should be able to upload browser data from an input[type=file] element using uploadBrowserData, I can find no reference to BlockBlobClient in the browser library source. I looked into modifying the browserify export scripts but I can't find any references in the main package source either. Also the example code suggests that using #azure/storage-blog gives you a BlobServiceClient by default:
const { BlobServiceClient } = require("#azure/storage-blob");
Is BlockBlobClient actually available in the JavaScript client library?
Okay I've figured this out, I need to use the Azure Storage client library for JavaScript, there's even a sample of doing exactly what I need to do. Now I just need to figure out how to bundle npm package files for use in Razor pages.

How to send an email with multiple attachments from Gmail using API client library for .NET

My app uses Google API client library for .NET to send emails with attachments.
When using Send(), I'm facing some limitations when it comes to file size of the attachments. So, I guess switching to Resumable upload as upload method may help. But it's pretty much undocumented.
Looking into source code, I guess using different Send() overload may be the way forward, but I can't figure out how to use it properly.
So, instead of attaching the files into message and calling it like this:
var gmailResult = gmail.Users.Messages.Send(new Message
{
Raw = base64UrlEncodedMessage
}, "me").Execute();
I should not attach the files to message and do something like following?
var gmailResult = gmail.Users.Messages.Send(new Message
{
Raw = base64UrlEncodedMessage
}, "me", fileStream, contentType).Upload();
The second version does not return any API error, but does nothing. I'm obviously missing something here.
How do I attach more than one attachment?
This is kind of an old question, but putting an answer here just in case anyone else needs it:
I was able to achieve this by converting my mime message into a stream (attachment(s) included), and then calling this overload on Send:
UsersResource.MessagesResource.SendMediaUpload googleSendRequest = service.Users.Messages.Send(null, "youremail#gmail.com", mimeMessageStream, "message/rfc822");
IUploadProgress created = googleSendRequest.Upload();
This will upload all of the attachments with the email message content and then send it off. I was able to send two 5 megabyte attachments in an email. Previously I was not able to send even one of those via the other Send method that takes in a base64 encoded mime message.

ckeditor 4.5 fileUploadRequest event not firing

I have a textarea with html id "id_textarea".
editor = CKEDITOR.inline( 'id_textarea', {
filebrowserBrowseUrl : 'browse_url',
filebrowserUploadUrl : 'upload_url'
});
editor.on( 'fileUploadRequest', function( evt ) {
console.log("This is not printing");
});
Whenever I try to upload a file, it doesn't print anything to console. Am I doing something wrong?
By the way, my requirement is to add csrf headers before sending a request for which I need to catch some event like fileUploadRequest.
I assume that you are trying to upload files via the Upload tab in the Image Properties dialog. It is provided by the File Browser plugin and fileButton which does not support the fileUploadRequest and fileUploadResponse events (there is already a feature request with a more in-depth description of this case).
If you would like to use these events for some custom request preprocessing, you can use the Upload Image plugin. The configuration process is described in the official docs, but keep in mind that it will work only for dropping or pasting files. Upload via the Image Properties dialog will still be handled by the File Browser plugin which does not support these events.
The important thing here is that since CKEditor 4.5.6, the File Browser plugin uses the CSRF header so it can be probably used on your server side without any modifications in the JavaScript code. So if you are using an older version I suggest updating to 4.5.6 (using e.g. CKBuilder) and trying to integrate with your backend. The CSRF header in the File Browser plugin should be sufficient for your needs.
Here is the header:

Is there any way to manually initiate an AJAX upload with the Kendo Upload control

I am doing an upload via CORS to Amazon S3 with the Kendo Upload control. I'm having an issue with the fact that I need to grab a signature from my server, then add it to the 'data' for the event object of 'upload' handler I created. The problem is, of course, that in the handler I fire off an async request to get the signature, and the upload handler continues on it's merry way without the signature data i need. The published API has no 'upload()' or something command that I could call when my async request returns.
I saw an ASP-Kendo-S3 example somewhere, but it's not exactly clear from that code, how that signature is being obtained, and of course, I'm not using ASP.
Kendo Upload has an onUpload event. In Kendo's asp.net example there really isn't anything specific to that framework that wouldn't port to anything else.
They populate the page initially with the profile (base64 encoded JSON).
To get a signature for that base64 encoded json profile they use this method (C#):
private static string Sign(string text, string key)
{
var signer = new HMACSHA1(Encoding.UTF8.GetBytes(key));
return Convert.ToBase64String(signer.ComputeHash(Encoding.UTF8.GetBytes(text)));
}
It looks pretty self explanatory to the point where you could port it to another language.

How can I send a picture in Java ME?

How can I send a picture in Java ME ? Maybe using base64 decode and the send in post form via http request
I think you looking for this image base64 encoding in J2me
Yes , I'm use that to send the base64 ,putting in
// write your picture data to os
os.write (data);
where data = String with a base64 image , the problem is that i don't have a base64 library that works in java and asp in the same way.
Have you considered using a "multipart/form-data" encoding type? If you so, then there is no need for Base64 encoding. See here and here for instructions on how to build the request.
If you still want to do the Base64 encoding, then you will be able to easily find many source implementations on the Web. If you are developing both the server and client side, you could use your own implementation on both ends.
There are plenty of coders in Base64 for Java. Apache commons has one, here is a standalone one.
HttpConnection connection = (HttpConnection) Connector.open("http://www.myserver.com");
connection.setRequestMethod(HttpConnection.POST);
connection.setRequestProperty("Content-Type","image/png");
OutputStream os = connection.getOutputStream();
// write your picture data to os
os.flush();
if (connection.getResponseCode() == HttpConnection.HTTP_OK)
{

Resources