Upload Files via API

New Member
12 0 0

@HunkyBill - I thought that assets were tied to the active theme so if the customer changes it or removes it, they'd lose their blog images, no? It's definitely an option but it seems like a bit of a hack since when you upload images in blog posts manually, they're uploaded to the admin files section.

 

@hj - cool, thanks for the info! I'll have to dig into that endpoint to see if we can make it work.

Product Customizer - Creating extremely customizable products within Shopify is no longer a hassle! BlogFeeder - Automatically pull updates from any RSS feed into your Shopify blog
0 Likes
Shopify Expert
2000 13 313

Good point. Substitute files for assets and you're set. Thanks HJ for bringing out the distinction. 

Custom Shopify Apps built just for you! hunkybill@gmail.com http://www.resistorsoftware.com
0 Likes
New Member
12 0 0

Ah no dice, there's no files scope for OAuth:

GET https://redacted.myshopify.com/admin/files.json

HTTP 403 Forbidden: {"errors":"Scope undefined for API access: files. Valid scopes: content, themes, products, customers, orders, script_tags, shipping, fulfillments, and gift_cards"}

Inspecting the request in the admin shows:

POST https://redacted.myshopify.com/admin/files/batch_create.json
name="files[]"; filename="test.jpg"

{"files":[{"key":"files/test.jpg","public_url":"http://cdn.shopify.com/s/files/1/0392/3962/files/test.jpg?7","created_at":"2014-03-28T11:43:25-04:00...;}]}

 

Looks like we'll need to wait until Shopify opens that API up. thanks for your help HunkyBill & HJ!

Product Customizer - Creating extremely customizable products within Shopify is no longer a hassle! BlogFeeder - Automatically pull updates from any RSS feed into your Shopify blog
0 Likes
Shopify Partner
202 0 23

Did you try adding a write_files scope to your OAuth?

Also assets and files do have a lot of similar attributes, so I assume their inner workings to be very similar.

Not very related to this topic but assets and files also support sizes the way product images support sizes. So to get a pico version of an image use:

http://cdn.shopify.com/s/files/1/0392/3962/files/test_pico.jpg?7

HJ

0 Likes
New Member
12 0 0

A good idea but it fails with an invalid_scope message:

OmniAuth::Strategies::OAuth2::CallbackError at /auth/shopify/callback
invalid_scope

 

Product Customizer - Creating extremely customizable products within Shopify is no longer a hassle! BlogFeeder - Automatically pull updates from any RSS feed into your Shopify blog
0 Likes
New Member
12 0 0

Shopify support advised this isn't on the roadmap, unfortunately.

Product Customizer - Creating extremely customizable products within Shopify is no longer a hassle! BlogFeeder - Automatically pull updates from any RSS feed into your Shopify blog
0 Likes
Shopify Staff
Shopify Staff
3 0 1

Might not be exactly what you were looking for but, for any other forum archaeologists, the GraphQL based Admin API has functionality for uploading images to a Shop. These such images are not directly associated to a particular Theme Asset or Product. See the docs at https://help.shopify.com/en/api/graphql-admin-api/reference/mutation/shopimageupload and https://help.shopify.com/en/api/graphql-admin-api/reference/mutation/stageduploadtargetgenerate

0 Likes
Shopify Partner
1 0 0

Hi Richard, is there any way to actually use that mutation? I can't find any way to give an app access to write_images.

0 Likes
Highlighted
Shopify Expert
2000 13 313

Ask Shopify to grant you write_images scope on the shop? If it can be done, they will likely do it for you.

Custom Shopify Apps built just for you! hunkybill@gmail.com http://www.resistorsoftware.com
0 Likes