OroPlatform Forums

Covering OroPlatform topics, including community updates and company announcements.

Forums Forums OroPlatform OroPlatform – How do I? Questions set attachment to entity on REST upload?

This topic contains 5 replies, has 2 voices, and was last updated by  oro6 6 years, 11 months ago.

Starting from March 1, 2020 the forum has been switched to the read-only mode. Please head to StackOverflow for support.

  • Creator
    Topic
  • #36469

    oro6
    Participant

    hello!

    we’ve extended a custom entity with oro attachments. this works very well in the oro backend, however, we also need to set an attachment when it gets uploaded from a user via a rest api. can someone point out how the correct way for this would be to convert uploadedFile to an oro attachment and store all this then via gaufrette?

    what I’ve found for now is to do it like this:

    but I am missing the conversion and the actual upload …

    thanks!

Viewing 5 replies - 1 through 5 (of 5 total)
  • Author
    Replies
  • #36470

    Mike Kudelya
    Participant

    Hi

    I have already explained how to create entities via API. Please use a similar approach to create a file and then a attachment.

    When user’s API key has been generated, you can look at json examples in our sandbox:

    File entity – [host]/api/doc/rest_json_api#post–api-files
    Attachment entity – [host]/api/doc/rest_json_api#post–api-attachments

    #36471

    oro6
    Participant

    Hi mike,

    thanks for your answer. I’ve found this too, but I can not use it, as we have built an own JWT based API for an external customers app. So there is no WSSE and no logged in ORO user in this case as we do not use the ORO API.

    I search for a programmatic solution to convert Symfony\UploadedFile (thats what I get from the upload) into an OroAttachment, move the files to attachment folder and add them as Attachment to an ExtendEntity.

    I know how to do that in plain Symfony, but I am missing the Oro attachment part here …

    Would it be possible to use the Oro API service in the controller somehow to convert and add the files?

    #36472

    oro6
    Participant

    ok, update: here is what I have right now:

    errors:
    1. persisting the file breaks because of the owner set in FileListener.php:40 ($entity->setOwner($this->securityFacadeLink->getService()->getLoggedUser());)
    –> fix: overwrite bundle?

    2. when the check is commented (for testing), the uplad works, the file gets persisted and the attachment is correctly created, but: it is then not visible in the oro frontend, but it seems to be correct in the database with all needed relations.

    –> fix: ???

    #36473

    Mike Kudelya
    Participant

    1.

    overwrite bundle?

    I think yes

    2. Did you enable attachments in the entity management ?

    #36474

    oro6
    Participant

    alright! i got it now. the trick was a) to explicitly set the organisation to the attachment and b) to override the FileListener thingy with an OverrideServiceCompilerPass.

    so this works now:

    :)

Viewing 5 replies - 1 through 5 (of 5 total)

The forum ‘OroPlatform – How do I? Questions’ is closed to new topics and replies.

Back to top