Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Dear Support,
I have faced an issue that if I upload the image through REST with a file tree (example: file[filepath] = public://post/test1/test2/test3/img5.jpg), I can upload it successfully, but the image style can't generate the image for node, hard to explain by words, please have a look the attached screen shot.
If I upload the image at root folder (example file[filepath] = public://img5.jpg), everything is normal, image style can generate, node also can show the image.
Thanks for reviewing the bug.
Comment | File | Size | Author |
---|---|---|---|
#17 | REST FIle upload_1.png | 45.78 KB | slhemanthkumar |
#17 | REST FIle upload.png | 50.09 KB | slhemanthkumar |
#12 | restupload 02.JPG | 73.9 KB | igetquestion |
#12 | restupload 01.JPG | 55.9 KB | igetquestion |
#11 | Capture3.JPG | 18.71 KB | facuchaer |
Comments
Comment #2
igetquestion CreditAttribution: igetquestion commentedComment #3
igetquestion CreditAttribution: igetquestion commentedComment #4
facuchaer CreditAttribution: facuchaer as a volunteer commentedHad the same exact issue, ussing "target_uri"... i need to save the file in a folder, already spend 4 hours on this.. tried to find an "official" documentation, but took me to pages and pages and pages of nothing. do you manage to get this working?
Comment #5
kylebrowning CreditAttribution: kylebrowning commentedYou can check the tests. We upload via that and attached to a node.
Comment #6
igetquestion CreditAttribution: igetquestion commentedDear kylebrowning,
Thanks for the reply, thanks for the module, I have been looking for someone to help look into the image path issue.
May I have more detail on how to REST upload an image with file tree? I have been stuck on this issue.
BTW, what do your mean "You can check the tests. We upload via that and attached to a node." ?
Thanks.
Comment #7
facuchaer CreditAttribution: facuchaer as a volunteer commented@kylebrowning, just checked the test page
there's nothing "special" about it. but i've tried to do it just like that and had the same results as @igetquestion
here the response:
my code:
p/d: im using "image" as alias for file resource.
Comment #8
facuchaer CreditAttribution: facuchaer as a volunteer commentedso.. news... i've been checking services code, and here is the issue:
on file_resource.inc
everything is ok unitl the "return array" part, is calling to serices_resource_uri with string file and fid as parameters
further debuggin on the services_resource_uri as states on the declaration takes "path" which is an array but it says containing the component parts of the path. and this is as far as i can get, since i don't know how services work but this where all gets the wrong way and returns wrong stuff.
but i can confirm if you change
to
everything works fine and also makes more sense (again i don't know about services internals, maybe im doing something extremly wrong).
Comment #9
kylebrowning CreditAttribution: kylebrowning commentedWell you're posting to `+ '/image.json';` Is that correct?
Cause in the test we are posting to `/file`
Comment #10
facuchaer CreditAttribution: facuchaer as a volunteer commentedmmmm.. don't get what you'r trying to point out with that. but changing to /file makes no difference.
here the response:
Comment #11
facuchaer CreditAttribution: facuchaer as a volunteer commentedjust checked with a co-worker, and it's ok.. the URI is not the content (file) url, it's the services endpoint url to obtain the file. my bad, all this time i was thinking that should retrieve the URI with "public//: etc etc). but calling to the reponse uri, gives u the real uri of the file. or full uri. here the request:
(with requested uri, you are saying the name as it's of the resource, note that if duplicated will give integrity costraint violation, use only filename with path).
gives as response:
{"fid":"599","uri":"http://localhost/knauf/v4_admin/adp/api/1.0/file/599"}
when calling to that uri (resource one):
....."uri":"public://typology/images/images.jpg"......... "uri_full":"http://localhost/knauf/v4_admin/sites/default/files/typology/images/images.jpg"........
EDIT:
@igetquestion, does this help with your issue? see this is not a bug, i think we miss understood how file upload works, and it's working as designed, maybe it's a feature request, but not a bug. let them know so the bug can be closed.
regards.
Comment #12
igetquestion CreditAttribution: igetquestion commentedDear facuchaer,
Im using chrome postman to test, but I get this return:
..........
"uri": "public://rest_upload\\node\\img5.jpg",
..........
"uri_full": "http://localhost/d755dev/sites/default/files/rest_upload/node/img5.jpg",
"target_uri": "rest_upload\\node\\img5.jpg",
..........
upload ok. I use filename with path for "file[filename]".
The "uri" and "target_uri" contain double backslash which making the image style cant generate image for node.
Can help on this?
Im been stack few weeks on this issue...
Thanks and regards.
Comment #13
marcingy CreditAttribution: marcingy as a volunteer commentedComment #14
facuchaer CreditAttribution: facuchaer as a volunteer commented@igetquestion have u tried without filepath? try only with filename (with path) im posting like that without problems. also try it and debug it on application... sometimes json responses cantain backslashes that are trimed when you decode them.
Comment #15
igetquestion CreditAttribution: igetquestion commented@facuchaer, Im tried but no luck, still the same issue getting double back slashes...
Can you help using windows chrome postman to test?
Comment #16
igetquestion CreditAttribution: igetquestion commented@facuchaer & @kylebrowning, I think im found out the issue in file_resource.inc at line 428:
"return implode(DIRECTORY_SEPARATOR, $directories);"
I changed to below line and solved my issue, but im still wish it can be review and officially updated for the future update.
"return implode('/', $directories);"
Im using WAMP in Windows system, "DIRECTORY_SEPARATOR" in windows system become double backslashes.
Comment #17
slhemanthkumar CreditAttribution: slhemanthkumar as a volunteer and at Cognizant Technology Solutions commentedTo get URI and Target URI same, we need to pass same value in the file path and file name. Please find the attached postman screenshots for more information. I'm using Drupal 7 and Servcies 3 module.
Regards
Hemanth