Creating Attachments

I am trying to create an attachment from a jpeg file.

What is wrong with my data syntax?

    logger.info(' ===== attachment_path: %s' % attachment_path)
    logger.info(' ===== attachment_name: %s' % attachment_name)
        
    attachment_data = { 'project': self._app.context.project,
                        'this_file': {'content_type': 'image/jpeg',
                                      'link_type': 'upload',
                                      'name':attachment_name,
                                      'url':attachment_path
                                      }
                        }
    
    sg_attachment = self._app.shotgun.create('Attachment',attachment_data,['id'])

===== attachment_path: /var/folders/vt/6bwbz02s6nsf2s1gj1gvmvf9g8sgjg/T/5fc5bb430a6c48bfa3485f01896cb279_sgtk.jpg
===== attachment_name: 5fc5bb430a6c48bfa3485f01896cb279_sgtk.jpg
Traceback (most recent call last):
File “/Volumes/Droid/PIPE/Shotgun/PipelineConfigurations/PIPE/Toolkit/install/app_store/tk-photoshopcc-addnote/v0.0.1/python/tk_photoshopcc_addnote/dialog.py”, line 153, in _on_add_note_btn_clicked
note)
File “/Volumes/Droid/PIPE/Shotgun/PipelineConfigurations/PIPE/Toolkit/install/app_store/tk-photoshopcc-addnote/v0.0.1/python/tk_photoshopcc_addnote/dialog.py”, line 274, in add_note_to_version
note_attachment = self.create_attachment(attachment_path)
File “/Volumes/Droid/PIPE/Shotgun/PipelineConfigurations/PIPE/Toolkit/install/app_store/tk-photoshopcc-addnote/v0.0.1/python/tk_photoshopcc_addnote/dialog.py”, line 310, in create_attachment
sg_attachment = self._app.shotgun.create(‘Attachment’,attachment_data,[‘id’])
File “/Volumes/Droid/PIPE/Shotgun/PipelineConfigurations/PIPE/Toolkit/install/core/python/tank_vendor/shotgun_api3/shotgun.py”, line 1240, in create
record = self._call_rpc(“create”, params, first=True)
File “/Volumes/Droid/PIPE/Shotgun/PipelineConfigurations/PIPE/Toolkit/install/core/python/tank/authentication/shotgun_wrapper.py”, line 63, in _call_rpc
return super(ShotgunWrapper, self)._call_rpc(*args, **kwargs)
File “/Volumes/Droid/PIPE/Shotgun/PipelineConfigurations/PIPE/Toolkit/install/core/python/tank_vendor/shotgun_api3/shotgun.py”, line 3169, in _call_rpc
self._response_errors(response)
File “/Volumes/Droid/PIPE/Shotgun/PipelineConfigurations/PIPE/Toolkit/install/core/python/tank_vendor/shotgun_api3/shotgun.py”, line 3465, in _response_errors
raise Fault(sg_response.get(“message”, “Unknown Error”))
tank_vendor.shotgun_api3.shotgun.Fault: API create() invalid/missing url hash string ‘url’:
{“url”=>
“/var/folders/vt/6bwbz02s6nsf2s1gj1gvmvf9g8sgjg/T/5fc5bb430a6c48bfa3485f01896cb279_sgtk.jpg”,
“content_type”=>“image/jpeg”,
“link_type”=>“upload”,
“name”=>“5fc5bb430a6c48bfa3485f01896cb279_sgtk.jpg”}

1 Like

Hi Soup!

Is your attachment path a local path? If so, you probably actually want the upload method.
https://developer.shotgunsoftware.com/python-api/cookbook/attachments.html#uploads

Uploads cannot be created directly on Attachments. Instead, you need to use the upload() method.

https://developer.shotgunsoftware.com/python-api/reference.html#shotgun_api3.shotgun.Shotgun.upload

Cheers!

4 Likes

Of course! :wink:

2 Likes

Hey @CGSoup—I changed the solution to be @Michael.Kessler’s reply so that people reading this thread in the future see that up top. :+1:

1 Like

I misunderstood the purpose of the Solution checkbox. Seems obvious now.

Daniel

2 Likes