Hi! @bouchep and @tony maybe you guys can help me? thanks!
Context:
I’m trying to migrate one project from a local hosted shotgun server (internet air gapped) to a regular shotgunstudios.com site on the internet, I’m copying everything: versions, tasks, users, pages, icons, statuses, shots etc. It is important that everything maintains the original created date for logging purposes.
My problem with Notes:
I try the method described here and here to create notes with attachments and annotations,
So shotgun uses the date to group replies, attachments, annotations and notes accordly
The problem is that I couldn’t achieve to create an attachment with a custom date, because I can’t update ‘this_file’ or ‘created_at’ after creation.
My approach:
Create a dummy attachment so it uploads the file to the cloud, then use the url generated to populate a creation data for a second attachment with the modified created_at, it kind of works, but I receive an incorrect token for the url provided, I guess I need to tweak something in the url for it to work.
My questions:
Can I edit somehow the url from the dummy attachment to make it work when populating the create data for the real attachment?
Can I use the sg._get_attachment_upload_info()
or sg._upload_to_storage()
directly to overcome this?
Any suggestions are appreciated thanks in advance!!
# find the original note that we want to copy
originalNote = sgSource.find_one("Note", [["id", "is", 6376]], ['created_at'])
# create a project-based dummy version to upload attachments to,
# if one doesn't already exist
dummy = sg.find_one('Version', [['code','is','dummyVersion']])
if dummy == None:
dummy = sg.create('Version', {'description':'dummy version to link files against','code':'dummyVersion','project':{'type':'Project','id':91}})
# filepath to the image
filePath = '/media/whatever.png'
# find the version you want to attach a note to
version = sg.find_one('Version',[['id','is', 6992]])
# upload a new Attachment to the dummy, the result is the id of the new Attachment
att_id = sg.upload('Version', dummy['id'], filePath)
# Get the first dummy attachment
dummyAttachment = sg.find_one('Attachment', [['id','is',att_id]],['created_at', 'this_file'])
# Create the real attachment using the dummy attachment this_file data except id
attachment = sg.create(
'Attachment',
{
'project':{'id':91,'type':'Project'},
'created_at':originalNote['created_at'],
'image': filePath
'this_file': {'content_type': dummyAttachment['this_file']['content_type'],
'link_type': dummyAttachment['this_file']['link_type'],
'name': dummyAttachment['this_file']['name'],
'type': dummyAttachment['this_file']['type'],
'url': dummyAttachment['this_file']['url']
}
}
)
# create the copy note now with the latest attachment
copyNote = sg.create(
'Note',
{
'project':{'id':89,'type':'Project'},
'created_at':attachment['created_at'],
'note_links':[version], #note_links expects an array of entity hashes
'content':'new simultaneous upload test',
'attachments':[{'type':'Attachment','id':att_id}]
}
)