Upload images from stream


Hi all,

I’m trying to implement an upload to Portfolio using C#. What I have is a byte array with the image data, but I can’t find how to upload it using a SOAP call. The only way I can add files now is by calling addAssetsByPath which requires a ‘physical’ file path. I want to prevent storing the image in the file system first and then call addAssetsByPath.

Any ideas?



Greetings Christ,

If you are uploading files to Portfolio, you should use the File Transfer Servlet to upload the file. This is the best way to upload a file. You can find out more about the File Transfer Servlet here http://doc.extensis.com/api/portfolio-server/FileTransfer.html and a code sample for using this function here: http://doc.extensis.com/api/portfolio-server/HTTPuploadFile.html#csharp

If you have any questions, please let me know.


Hi Matt,

I’ve successfully used the servlet for uploading files. I wonder if it is also possible to have similar functionality in the SOAP api.




We experimented with similar functionality in the SOAP API, but what we found is that, for larger items, there was a greater chance of Java Heap errors in the Portfolio Server. The HTTP Servlet allows us to stream larger files up to the server, where that would not be an option with a SOAP based command.



Hi again,

I’ve tried using the File Transfer Servlet succesfully, but when I use the GetResponse() on the webrequest I always get an exception and I don’t know how to solve that. The exception details are:

System.Net.WebException was caught
Message=The remote server returned an error: (500) Internal Server Error.
at System.Net.HttpWebRequest.GetResponse()
at Adlib.Portfolio.Imaging.Plugin.PortfolioImagePlugin.UploadToPortfolio(String id, Byte[] content) in c:\Data\TeamProjects\devc#2009\PortfolioImagePlugin\PortfolioImagePlugin.cs:line 195

Is there something wrong in the IIS configuration?

Thanks again,



My first question is did the file actually get added to the catalog?
After a successful addition, the getResponse should be returning the ItemID of the newly cataloged file. The fact that you are getting a 500 error makes me wonder if the file was successfully added.

Look in the catalog to see if it has been added.
Also take a look at the server.log in the Portfolio Logs folder and see if an error was recorded there. ( Portfolio Server/logs/server.log )

If the file has been successfully added and there are no errors in the server.log, then we’ll take a look at your code and see if we can identify what the problem might be.



Hi Matt,

So, I checked the catalog and found that the file is added correctly. Checking the log however showed the following result:

2013-09-24 09:17:09,772 [632657C6-EEE5-813E-81E8-C368DF5BC982] INFO [extensis.portfolio] new session created: userName=christ, sessionId=4ECE1124-B7A8-7987-819C-1B6E382F0C5D
2013-09-24 09:17:09,855 [] INFO [extensis.portfolio] Asset Upload Servlet: POST with params: catalog: portfolio-adlib writing to path: C:\AdlibWatchFolder filename: Tarsier 10.PNG
2013-09-24 09:17:09,865 [] ERROR [extensis.portfolio] OperationInvalid
extensis.portfolio.legacyserver.portfolio.PortfolioException$ServerError: OperationInvalid
at extensis.portfolio.legacyserver.portfolio.PortfolioExceptionFactory.create(PortfolioExceptionFactory.java:28)
at extensis.portfolio.legacyserver.fetch.FetchServer.serverErrorException(FetchServer.java:2383)
at extensis.portfolio.legacyserver.fetch.FetchServer.receiveResponse(FetchServer.java:1217)
at extensis.portfolio.legacyserver.fetch.FetchServer.receiveJsonResponse(FetchServer.java:1249)
at extensis.portfolio.legacyserver.fetch.FetchServer.receiveJsonResponse(FetchServer.java:1262)
at extensis.portfolio.legacyserver.fetch.FetchServer.addAsset(FetchServer.java:1470)
at extensis.portfolio.server.service.FileTransferServlet.uploadAsset(FileTransferServlet.java:347)
at extensis.portfolio.server.service.FileTransferServlet.doUpload(FileTransferServlet.java:231)
at extensis.portfolio.server.service.FileTransferServlet.doPost(FileTransferServlet.java:497)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:172)
at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:175)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:470)
at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:74)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
at org.jboss.web.tomcat.tc5.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:156)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:879)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:113)
at java.lang.Thread.run(Unknown Source)

Not sure what this means. Fyi: we’re using Portfolio Server 10.

Regards and thanks again,



I’ve sent you a private message on this subject. I’d like for you to Email me directly.
If you did not get the message, please let me know.




I’ve reviewed your code and it looks like the problem has to do with an extra colon in the address of the upload directory.
Your code reads:
String destination = “::PORTFOLIO:address:on:server[color=#0000FF]:[/color]”;
When it should read:
String destination = “::PORTFOLIO:address:on:server”;

The extra colon on the end of the address is the source of the problem. If you find you are still having problems after making that change, please let me know.



This “fixed” it for me, too, but what’s broken here is the documentation for the API:

Do NOT use the online example here: http://doc.extensis.com/api/portfolio-server/HTTPuploadFile.html#csharp

It clearly illustrates the method of creating the 500 error on line 7: :confused:



Thanks for pointing that out. The documentation has been updated and the error has been corrected.
For some reason I thought this had been resolved a while ago. I’m not sure how it got missed.

It should be safe to use that online example now. :smiley:



Thanks, Matt. I know others will benefit from that correction. It sure threw me for a loop.