[SOLVED] Uploading image?

All Union Platform questions, comments, feature requests, and bug reports.

Uploading image?

Postby Cuteless » Tue 21 Apr 2015 02:38

Anybody has some advice on writing custom module for uploading images to server? The uploading part is what I'm interested.
Cuteless
 
Posts: 8
Joined: Sat 24 Aug 2013 03:14

Re: Uploading image?  

Postby toby » Thu 30 Apr 2015 02:37

Virtually anything you do involves sending data to the server,
so you just need the appropriate message.

Here's one approach:
It may or may not be the best way, but it's the first thing that came to mind.

For a model you can use the Union Chat Room example.
Just replace the chat that's sent with your image data.

You'll need a module to receive the data.
It can either be a server module, or a room module.
This example uses a room module, but a server module example would be similar.

From the client side, use something like this:
msgManager.sendUPC(UPC.SEND_ROOMMODULE_MESSAGE, roomID, "image-data", "thedata|"+imagedata);
(A server module message will be similar.)

Now that straightforward call might need some preparation for a couple of reasons.

- Image data is probably binary, so you might want to convert it to some text-form representation,
such as hexadecimal or base-64 encoding.

- Image data can be be large (as in megabytes, etc) so you might want to break it up into parts.
Just add more arguments:

msgManager.sendUPC(UPC.SEND_ROOMMODULE_MESSAGE, roomID, "image-data", "part-number|" + p + " of " + n, "thedata|" + imagedata);

Then you need to write the receiving code in the module on the server side
which decides what to do with the image once it has it.
toby
 
Posts: 162
Joined: Sun 24 Jun 2012 14:18


Return to Union Platform

Online

Users browsing this forum: No registered users and 1 guest