Nam Vu
Nam Vu

Reputation: 5725

How can i upload to Alfresco from Android?

I want to upload to Alfresco via my Android apps. I find out this api:

   The following web script uploads file content and metadata into the repository.
POST /alfresco/service/api/upload
The web script uses the following HTML form data:
filedata - (mandatory) HTML type file
siteid
containerid
uploaddirectory
updatenoderef
filename
description
contenttype
majorversion
overwrite
thumbnails
The returned content is:
nodeRef
It returns a status: STATUS_OK (200).
The web script description document specifies the following options:
Value   Description
user    The authentication access
required    The transaction level
any The format style
json    The default response format

But i dont know

  1. where's my file path?

  2. filedata - (mandatory) HTML type file : what's the format of HTML type file, and what's is this?

  3. And what about other parameter?

Thanks for your reading

Upvotes: 0

Views: 784

Answers (2)

Will Abson
Will Abson

Reputation: 1572

First of all I am assuming that you are are using a HTTP client library to make that POST call, and that that library is capable of encoding the POST body in multipart/form-data format, simply known as 'Multipart'.

The filedata parameter should contain both the content and the name (on your filesystem) of the file being uploaded. This is the advantage of multipart encoding, and your HTTP library should know how to encode the parameter if you simply pass it a reference to the file and tell it to use multipart/form-data format.

Other parameters are simply string values, so should be more easily set. The documentation in this area is not great but it should be obvious from the parameter names in general what they do.

You could try getting the upload process to work from your local machine using Curl, and then working out how to apply a similar process in your app, e.g.

curl -H "Content-type: application/json" --data '{ "username": "admin", "password": "admin" }' http://localhost:8080/alfresco/service/api/login

grab the login ticket from the output, then upload a test file named test.png from the local file system to a site with the URL name willtest,

curl -F '[email protected]' -F 'siteid=willtest' -F 'containerid=documentLibrary' http://localhost:8080/alfresco/service/api/upload?alf_ticket=TICKET_blah

then finally log out

curl -X DELETE 'http://localhost:8080/alfresco/service/api/login/ticket/TICKET_blah?alf_ticket=blah'

One last but important note: A full mobile SDK for Android is in the process of being developed by Alfresco for release later this year. If you intend to do something more complex than simply uploading a file, you might want to look at that when it is available.

Upvotes: 2

Nam Vu
Nam Vu

Reputation: 5725

To be able to upload files from an Android application and use the Multipart content type i need to add some additional jar files to my application.

apache-mime4j, httpclient, httpcore and httpmime

And use HttpPost to post parametter

Upvotes: 0

Related Questions