Third Light Developer Exchange

Code and templating community forum for developers and software integrators

You are not logged in.

Announcement

If you wish to join the Developer Exchange, please contact your account manager - this is to avoid unnecessary spam in the forums. Many thanks for your understanding.

#1 2015-02-24 14:26:01

mdyason
Member
Registered: 2015-01-20
Posts: 43

Upload.AddFilesToUpload

I am trying to use the Upload.AddFilesToUpload method to add a file that needs to be uploaded to an upload job.

The API documentation shows the “fileData” as consisting of 4 variables.  (I assume they all have to be present?)
The second one is a string for the name of the file.    What exactly should this look like?  Surely it has to include a path?  The system does not seem to like “C:/x/y/z.jpg” where x and y are folders and z is the actual filename. 
The third one, “data” must be the file contents, encoded to the encoding specified.  Now if my file is an image, how do I encode the image?  What if the image is many megabytes – the resulting string is going to be enormous?

My first attempts looked as follows:

POST /api.json.tlx HTTP/1.1
Host: imstest.matrix-solutions.com
Content-Type: application/json

{"apiVersion": "1.0.1", "action": "upload.AddFilesToUpload","inParams": {"uploadKey": "2c2yFkxxe2HyL2D.SGA2", "fileData":{"encoding": "base64", "name": "c:/junk/somePhotos/unusableSunset.jpg", "data": " ", "metadata": " "}}, "sessionId": "oYeyetmzuQnUjQZL6qkprccW,vNnCUuU" }

I have tried variations on the above but they all give error messages.  The sessionID came from core.loginWithKey while the uploadKey comes from upload.createUpload.  Also can anyone tell me how long the uploadKey remains active - does it timeout?

Offline

#2 2015-02-24 15:02:21

steve
Third Light Staff
Registered: 2013-06-06
Posts: 105

Re: Upload.AddFilesToUpload

Hi mdyason,

The "name" parameter should be set to the name of the file as you would like to see it inside IMS. The filepath of the source file isn't relevant in this context.

You are correct that "data" holds the holds the file contents but a more efficient method would be to use the approach documented here:

https://secure.thirdlight.com/developer … .php?id=17

Best Regards,
Steve

Offline

#3 2015-03-02 18:59:17

dominic
Third Light Staff
Registered: 2013-06-06
Posts: 119

Re: Upload.AddFilesToUpload

Hi,

To add some further notes on this:

The 'fileData' parameter is a hash of hashes - with the first layer of keys being user-selected, unique references that would be returned by subsequent status queries. For example:
"fileData":{"fileOne":{"encoding":"base64","name":"firstfile.png",data:"iVBORw0KGgoAAAANSUhEUgAAAoAAAAGQCAYAAAA+89E="}}

The metadata sub-key is optional, however if present it should be a hash keyed by metadata tag (e.g. {"caption":"An example file"})

Kind regards,

Dominic

Offline

#4 2015-03-03 19:14:28

mdyason
Member
Registered: 2015-01-20
Posts: 43

Re: Upload.AddFilesToUpload

Thank you Dominic.  After having no luck with the POST a file I came back here to try again.  Used a tiny image so data was small.

Process is as follows:

After logging in run createUpload:

POST /api.json.tlx HTTP/1.1
Host: imstest.matrix-solutions.com
Content-Type: application/json

{"apiVersion": "1.0.1", "action": "Upload.CreateUpload", 
"inParams": { "params": {"destination": "28168108553", 
                        "synchronous": "true", 
                        "lifetime": "60", 
                        "editablemetadata": { "caption": "OPTIONAL" }, 
                        "allowotheruserupload": "true" }}, 
"sessionId": "ffnnsRJzTI6Dt3tohNEU8cqu,iwtgKwt" }

result: 
{"result":{"api":"OK","action":"OK"},"outParams":{"uploadKey":"ZKZEvgjjiZFa6ZTX6ef","postURL":"https:\/\/imstest.matrix-solutions.com\/dofileupload.tlxr?task=ZKZEvgjjiZFa6ZTX6ef"}}

Try add file to upload:

POST /api.json.tlx HTTP/1.1
Host: imstest.matrix-solutions.com
Content-Type: application/json

{"apiVersion": "1.0.1", "action": "upload.AddFilesToUpload",
"inParams": {"uploadKey": "ZKZEvgjjiZFa6ZTX6ef",
            "sessionId": "ffnnsRJzTI6Dt3tohNEU8cqu,iwtgKwt",
            "fileData":{"fileOne":{"encoding": "base64", 
                                    "name": "Magnifier.jpg", 
                                    "data":"/9j/4AAQSkZJRgABAQEAlgCWAAD/2wBDAAoHBwkHBgoJCAkLCwoMDxkQDw4ODx4WFxIZJCAmJSMgIyIoLTkwKCo2KyIjMkQyNjs9QEBAJjBGS0U+Sjk/QD3/2wBDAQsLCw8NDx0QEB09KSMpPT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT3/wAARCAAlACUDASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSExBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tPU1dbX2Nna4uPk5ebn6Onq8vP09fb3+Pn6/9oADAMBAAIRAxEAPwCpdXUVpA0077Il6t6VmHxPpP8Az9j/AL5NHic58P3X0H865TwTpNtrfiuysrwEwyP8wHfHagD0LTra41ezF3YRNLbk4D4xmqd3fw6fqAsbtzFdEgBCOufevX49JhtYo4YEWOKIBQijAC1xnxB0bTp4YL3YfNhlGxxwfpWvs01ozNTd7WOdDUVCHzRWRoZviY/8SG5+g/nVb4beFL69vhrAk+y29t8yysPvGtTUIoZLYrcxvLCWXeiD5iM9qd4v8VXJso9K8O2csNmqgblXGa5q86qajSWr6m9KEGnKbPRdP+IuiXEUkN/exQ3MB2vk8N7j/CuA8afEO11e+i0nSkEkPnKzXJ/i9gK8ybTL9mJa2mJPUkVZ0zTbyPUrd3tpAocEkr0rrUmlY53FOVzvQ3WigL1oqRlphUDfWiigCJhz1NOUe5oooAlVRiiiigD/2Q==", 
                                    "metadata": {"Caption":"Magnifier"}}}}}

result:

{"result":{"api":"OK","action":"UPLOAD_NOT_FOUND"}}

What am I still doing wrong?

Last edited by mdyason (2015-03-03 19:15:46)

Offline

#5 2015-03-03 21:14:58

dominic
Third Light Staff
Registered: 2013-06-06
Posts: 119

Re: Upload.AddFilesToUpload

From the query quoted, it looks like you have sessionId within inParams, rather than as a sibling key (as used in the previous call). That would cause this effect, as effectively the call is anonymous, so does not have access to see the (private) upload job.

Offline

#6 2015-03-03 22:30:15

mdyason
Member
Registered: 2015-01-20
Posts: 43

Re: Upload.AddFilesToUpload

Oh - another stupid error on my part - thank you.  The biggest problem here was the life of the upload being set at 60 seconds.  That's not enough time to mess around with bits of code.

Offline

Board footer