Uploading Files with the API


If you were to ask the question of what you can do with the Portfolio API, then resulting answer would be several posts long, because what you can do is limited by your imagination. Basically, you can do a lot. So lets focus on one aspect. Uploading Images!

One particular type of tool you can create is a File Uploader. The scenario we are looking at is that your company wants people to upload files to Portfolio, but they do not want them access to the catalog. Just upload the files, maybe assign a description and couple keywords. That is it!
The Desktop Client and the WebClient are out, because they provide too much access. Netpublish is the wrong tool, because it is read-only. You could provide access to an FTP site, but then the person uploading the files would not be able to add any metadata. This brings us to our Upload Tool.

I’ve attached a simple PHP tool for you to examine. This is a very basic program. When loaded in a web browser, it will prompt you for an IP address, a username, and password. Once connected to the Portfolio Server, you will see a form.

First: Choose a catalog. This will only list catalogs that contain watchfolders.
This is a very basic script, so it will not list sub-folders, though that is possible. It will grab the first watchfolder and upload to the root of it.

Second: Fill in the name of the User uploading the file. In my script, this will fill in the ‘Approved By’ field. But you can change that to a field of your choice.

Third: Add some keywords. You can add several with a comma delimiter.

Fourth: Description. Enter in a nice summary of the image you are uploading.

Finally: Choose a file. A 500 pixel height preview of the image should appear, but results may vary.

Once you have filled in the form, click Upload. The image you have chosen should be uploaded to the Portfolio server. Once complete, the form will reload with a message at the top, letting you know if your upload has succeeded. It will also present you with a now empty form, so that you upload an additional image. When you are done, click log out.

If you check out your images in Portfolio, you will see that your metadata has been added to it.

What’s going on behind the scenes?

The API is handling the process in two parts. First it uploads to file to the FileTransfer servlet. Once that is complete, the servlet returns a Record ID. The script then uses that Record ID for the second step, updating the metadata. It builds an AssetQuery searching for the Record ID, creates some FieldChanges with the Metadata changes, and updates the record with an updateAssetFieldValues().

As I said, this is a very basic tool. It gets the job done, but that’s about it. There is no error handling, there is no CSS to make it pretty, and the tools are very basic. But it works, and it is a base for you to use to make something amazing.

Download the code. Look at what I have done and think about how much better you can make it. If you have questions, ask.

Now go forth, do!
PSupload.zip (161 KB)