ssossossosso

Forums

Covering OroCRM topics, including community updates and company announcements.  Subscribe

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

  • Creator
    Topic
  • #34530

    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
  • #34564
    Mike Kudelya
    Mike Kudelya
    Oro Core

    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

    #34613

    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?

    #34617

    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: ???

    #34619
    Mike Kudelya
    Mike Kudelya
    Oro Core

    1.

    overwrite bundle?

    I think yes

    2. Did you enable attachments in the entity management ?

    #34626

    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)

You must be logged in to reply to this topic.