Forum Discussion

tripp-bishop's avatar
10 years ago

Uploading image to album from within an End Point

Hi,

 

I'm currently using a direct call to the following REST API method:

/users/id/${user.id}/media/albums/default/public/images/upload

 

to get an image uploaded to a user's album. What I'd like to do is wrap this call in an endpoint so that I can do some additional processing at the same time. I haven't found a way to get this to work, however. Is this possible or do I have to make this call directly in order to work properly? Thanks!

 

Cheers,

 

Tripp

6 Replies

  • tripp-bishop - Yes, you can add any custom code in your endpoint before the processing of image upload. You may create an Endpoint.

     

    //Code to process XYZ things
    
    //Code to upload the image
    
    //Code to process XYZ things

     

  • tripp-bishop's avatar
    tripp-bishop
    Mentor
    10 years ago

    VarunGrazitti Thanks! I'm running into an interesting issue:

    Here's the content of my test endpoint:

    <#assign status = "error" />
    <#assign message = "no errors" />
    <#assign upload_payload = http.request.parameters.name.get("image.content", "") />
    <#compress>
        <#attempt>
            <#assign response = rest("/users/id/${user.id}/media/albums/default/public/images/upload?image.content=${upload_payload}") />
            <#assign status = "success" />
        <#recover>
            <#assign message = .error />
        </#attempt>
    </#compress>

    and this is the test form that is submitting to the EP:

    <form method="post" action="/my-path/upload-test" enctype="multipart/form-data">
        <input type="file" name="image.content"><br />
        <input type="submit" value="Upload" /><br />
    </form>

     

    So super simple. What I'm seeing is that the line:

    <#assign upload_payload = http.request.parameters.name.get("image.content", "") />

     

    is setting the variable "upload_payload" to an empty string, probably because we failed to find a request param called "image.content". Is there another way I should be getting at the image.content variable that's being uploaded by the form?

    Thanks for your help!

     

    Cheers,

     

    Tripp

  • tripp-bishop's avatar
    tripp-bishop
    Mentor
    10 years ago

    So I've done a little more testing on this and noticed something:

    I added a new field to the form:

    <input type="text" name="image.title" value="The light is green" />

     

    and I commented out the "file" input field.

     

    Submitting the new form to the endpoint I found that the new field is also not found. So I removed the form's enctype attribute and resubmitted the form and the image.title parameter is now found and shows the correct data. So it appears that the multipart/form-data enctype is confusing the endpoint (or at least http.request.parameters). Any thoughts on this?

    Cheers,

     

    Tripp

  • DougS's avatar
    DougS
    Khoros Oracle
    10 years ago

    Unfortunately we don't have the support right now in our customization layer to read files from multipart/form-data requests.  I'd like to encourage you to submit a product idea for this -- I'll vote for it, because this there should be support for this.

  • tisawyer's avatar
    tisawyer
    Contributor
    9 years ago

    Any update on this feature? I am trying to do the same thing: post a form to an endpoint with a file to be uploaded.