Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upload product's images #27

Open
salamichel opened this issue Jul 28, 2018 · 8 comments
Open

Upload product's images #27

salamichel opened this issue Jul 28, 2018 · 8 comments

Comments

@salamichel
Copy link

Hi Michal!

Every seems ok, on create, update or delete items (product, taxon etc)

But I can't figure out how to upload image on products. i have tried to push an array of file path in create function as this

$images = [
dir . '/../ressources/images/logo.jpg',
];
$productsApi->create($article, [], $images);

How send image to sylius via API ?

Please help

regards

@coderiekelt
Copy link

Were you able to figure anything out, @salamichel?

@coderiekelt
Copy link

Solved it

WHAT YOU NEED TO DO:
For every image you want to add, add an entry to the 'images' array in your DATA, with in it an array containing key: type, value: the name you want to give the type.

NEXT:
Add your images as followed: e.g. $images['images[0][file]'] = $filepath;.
Now add that $images variable as your files, and your images will appear :)

Only took two hours of annoyed Google searches and swearing, enjoy anybody who may stumble accross this.

@cypherfunk
Copy link

Dude you helped me such much with your comment

@sherif807
Copy link

Man !!!!!!!!!!!!!!!!!!!!!!!!!!!!!... Thank you so much. Days and days of trying. finally your comment... Thank you sooo much.

@kumarSaurabh27
Copy link

kumarSaurabh27 commented Feb 13, 2020

Hi @salamichel, @sherif807, @cypherfunk, @coderiekelt

I am using create product API (post) method, this is my API's body:

{
    "code":"test",
    "translations":{
        "en_US":{
            "name":"test",
            "slug":"test",
            "description":"This is test product"
            }
    },
    "images": [
        {
            "type":"pro1",
            "file": "4/5/8/1/4581ab0caddd4b3d24f2a973d273ce9e8ae7bea6_uv.png"
        }
    ]
}

Can anyone please explain me how should I format code for image so that it gets accepted??
The product is being created but not the image. Can you please help?
This is how I am receiving my image in controller:

array:1 [
  0 => array:3 [
    "locale" => null
    "scope" => null
    "data" => "4/5/8/1/4581ab0caddd4b3d24f2a973d273ce9e8ae7bea6_uv.png"
  ]
]

@Krishan29
Copy link

Hi @coderiekelt
Can you please elaborate some more info about where to put the $images variable in the request data?
Actually I am sending as below but the image is not creating.
Can you help?

"code" => "test1"
"productTaxons" => ""
"channels" => array:1 [
0 => "FASHION_WEB"
]
"images" => array:1 [
0 => array:2 [
"file" => Symfony\Component\HttpFoundation\File\UploadedFile {#4178
-test: false
-originalName: "ee275acf9e7bcd61c705744c071b70537016a470_fd70e285b38e2a5a60cb486805fb7e8f933c6e00_trophix_36"
-mimeType: "application/octet-stream"
-size: null
-error: 0
path: "/home/users/krishna.kant/www/html/pim-community-standard/app/file_storage/catalog/e/e/2/7"
filename: "ee275acf9e7bcd61c705744c071b70537016a470_fd70e285b38e2a5a60cb486805fb7e8f933c6e00_trophix_36.png"
basename: "ee275acf9e7bcd61c705744c071b70537016a470_fd70e285b38e2a5a60cb486805fb7e8f933c6e00_trophix_36.png"
pathname: "/home/users/krishna.kant/www/html/pim-community-standard/app/file_storage/catalog/e/e/2/7/ee275acf9e7bcd61c705744c071b70537016a470_fd70e285b38e2a5a60cb486805fb7e8f933c6e00_trophix_36.png"
extension: "png"
realPath: "./app/file_storage/catalog/e/e/2/7/ee275acf9e7bcd61c705744c071b70537016a470_fd70e285b38e2a5a60cb486805fb7e8f933c6e00_trophix_36.png"
aTime: 2020-06-01 18:20:54
mTime: 2020-06-01 18:18:55
cTime: 2020-06-01 18:18:55
inode: 19529734
size: 314470
perms: 0100644
owner: 1282
group: 500
type: "file"
writable: true
readable: true
executable: false
file: true
dir: false
link: false
}
"type" => "Main"
]
]
"associations" => array:1 [
"similar_products" => ""
]
"enabled" => false
"translations" => array:1 [
"en_US" => array:3 [
"name" => "name"
"slug" => "test1"
"description" => "

des

"
]
]
]

@Krishan29
Copy link

Hi @coderiekelt

I hope you are doing well.
Is there any update on this?
Actually we are using Sylius API to create a product from Our PIM(Product Information Management) to sylius and getting this issue.
So it's very important for us.

Thanks in advance.

@xEndLe
Copy link

xEndLe commented Apr 6, 2022

Hi @Krishan29, any update on this? Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants