1

I have a folder say "MyFiles" where I have lots of files. Now I need to upload those file via REST over HTTP . What will be the approach?

I tried the below but it is wrong

<flow name="testFlow1" doc:name="testFlow1">
        <http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8081" doc:name="HTTP"/>


         <http:rest-service-component 
                                serviceUrl="http://localhost:8280/rest/xyz" 
                                httpMethod="POST"> 
         </http:rest-service-component> 

    <http:endpoint host="localhost" port="5430" encoding="UTF-8" 
                method="POST" connector-ref="fileHttp" path="fileuploader" name="muleFileUploader">
       </http:endpoint>

</flow>

Please help. Since the input folder will have multiple files, how can we achieve that also?

Thanks

priyanka.sarkar
  • 25,766
  • 43
  • 127
  • 173

1 Answers1

2

Your flow doesn't use a file inbound endpoint and uses a generic (non-in non-out) HTTP endpoint so there's no way this can work.

Below is a configuration that successfully uploads files to an HTTP endpoint. I can not make it work without the object-to-byte-array-transformer (the same file gets polled over and over again - bug?), so I hope your files are not huge...

<flow name="fileUploader">
    <file:inbound-endpoint path="/tmp/mule/in"
        pollingFrequency="5000" moveToDirectory="/tmp/mule/done" />
    <object-to-byte-array-transformer />
    <http:outbound-endpoint address="http://..."
        method="POST" exchange-pattern="request-response" />
</flow>
David Dossot
  • 33,403
  • 4
  • 38
  • 72
  • Hi, I am getting this: INFO 2013-01-23 16:14:04,222 [[fdsffsdfd].fileUploader.stage1.02] org.mule.transport.http.transformers.ObjectToHttpClientMethodRequest: Content-Type not set on outgoing request, defaulting to: text/plain. and the file is not moving to the desired http location.Moreover, the file can be of any type say text, pdf, image file, movie file etc. – priyanka.sarkar Jan 23 '13 at 10:49
  • Not sure by what you mean by "file is not moving to the desired http location": any error? What does the receiving end gets? More info please. If you need the exact mime-type to be used with the HTTP POST, you'll have to set it yourself with a custom transformer that analyzes the file extensions and sets the `Content-Type` message property to the desired value (there are helper classes you can use for the extension->MIME translation). – David Dossot Jan 23 '13 at 16:18