Uploading images in Code Studio

Hi, I’m trying to add the functionality to upload images within the Code Studio, however I’m having trouble working out how to achieve this.

I’m assuming that I need to use the record.save_uploaded_files function to do this, but I can’t find any reference to a URL that I need to upload the images to.

Has anyone had any success doing this, or am I missing something obvious?

Thanks, Ewan

Hi Ewan - welcome!

I’m a big believer in not reinventing the wheel! Take a look at the drop-zone widget on the appShare.

There are two bits of interest. In the get_settings, there is a setting file_path that defines a relationship to a file object which will be used to upload:

			main_label:'Relationship to file object',
			settings: {
				required: true

Then there is the use of this parameter and you were almost there:

	var item = cs.record(widget.get_base_record_id());
	var result = item.save_uploaded_files(widget.get_setting('file_path'));

(with one quick modernisation edit to “cs.”…

1 Like

Thanks Richard,

Am I right in thinking that “file_path” is just where the file is going to be saved, not the path to the file itself?

If so, where does the actual uploading of the file come in to this, as in how does it know which file is being uploaded into this path if that makes sense?

Hi Ewan

“file_path” is just a label - as long as it matches between the two references above you are ok. However the setting it is labelling is a relationship to your base object - and would normally be one to many to a file object. If you publish your code and drop the widget onto a page, you will see it in the settings for the Widget on the build page - where you can give it a value. When you call “save_uploaded_files” it will create an object of the appropriate type for each file and relate them back to your base object.

Of course, the drop zone widget may be your best starting point…

And if I am totally wrong and you are not building a widget, then you can replace file_path with a reference to a relationship.