The website encountered an unexpected error. Please try again later.
GuzzleHttp\Exception\ConnectException: cURL error 6: Could not resolve host: http (see http://curl.haxx.se/libcurl/c/libcurl-errors.html) in GuzzleHttp\Handler\CurlFactory::createRejection() (line 186 of vendor/guzzlehttp/guzzle/src/Handler/CurlFactory.php).
SOLVED
1- I installed File Entity module: https://www.drupal.org/project/file_entity
2- I assign administration role to my user which is I request services with it's basic auth info.
hi i am trying to post image from api but the file is not copied it is creating .tmp file i.e file1.tmp something like that my orginal file is not copied to the druapl fo;lder location please help me if anyone has solution
How procede for private files managed by drupal.
Using this api with private configuration compairs file node with broken attachment. The files on other hand are correctly trasferred to the server web. Have i to add extra parameters to the post?
The instruction for a public configuration run correctly crating a node with accessible file.
Hi All,
I am implementing react js in front and Drupal as backend, Now Suppose I am creating article type node, I am taking form input, then passing POST type request to drupal and creating article everything is working good, now I want to post image as well for the article with the same request that being sent for article creation, How can send image with rest fields like title, body and so on.
like react code something below:
Finally, I managed to deliver the file to the server, but then the error 500 rased due destination folder not set. I can't figure where to define this destination directory: in request JSON data or header, or somewhere else in the settings.php or somewhere in REST configuration?
Edited this source core/lib/Drupal/Core/File/FileSystem.php line 488 in order to print the $destination, and it appears to be empty. See '' in the server log below:
H01071: Got error 'PHP message: Uncaught PHP Exception Drupal\\Core\\File\\Exception
\\DirectoryNotReadyException: "The specified file 'temporary://filemDIAwD' could not be copied
because the destination '' directory is not properly configured. This may be caused by a problem
with file or directory permissions." at /var/www/vhosts/web.site/core/lib/Drupal/Core/File
/FileSystem.php line 488'
Tried to define 'file_private_path' folder in settings.php, added 'tmp' folder under 'sites/default/files' but with no result. What am I missing here?
@kiamlaluno how can we get the answer to the question asked by @AntonioPC
As I am facing the same issue. I am getting the following error by running the above API :
{
"message": "Could not determine entity type bundle: \"type\" field is missing."
}
Can you at least provide a link so that we can solve this issue?
Comments
Comment #2
wim leersYou can't yet, we're fixing that in #1927648: Allow creation of file entities from binary data via REST requests.
Comment #4
pranilkochar commentedhii, im using DRUPAL 8.1.8 but not able to post a file using rest api
Comment #5
pranilkochar commentedmy url=http://localhost/entity/file
request body:
{"_links":
{
"type":{"href":"http://localhost/rest/type/file/file"},
},
"filename":[{"value":"pranil.jpg"}],
"filemime":[{"value":"image/jpeg"}],
"data":[{"value":"base64 content"}] }
error:
{
"message": "A fatal error occurred: cURL error 6: Could not resolve host: http (see http://curl.haxx.se/libcurl/c/libcurl-errors.html)"
}
any suggestions?
Comment #6
HAMMAMI_IMED commentedthe same problem.im using DRUPAL 8.2.0 but not able to post a file using rest api. I need help
Comment #7
shruthiganesh commentedhref to upload image is "http://localhost/rest/type/file/image"
Comment #8
a.gursoy commented[Note: I found solution myself. Check below]
I tried to change href as described #7 but result is same :/
POST
drupal8.loc/entity/file?_format=hal_jsonBODY
RETURNS
SOLVED
1- I installed File Entity module: https://www.drupal.org/project/file_entity
2- I assign administration role to my user which is I request services with it's basic auth info.
And problem solved.
Comment #9
vjsutar commentedFor Drupal 8.3.x
POST: authentication: basic_authentication, formats: hal_json, json
URL:
Header:
Method:
Body:
Response:
Comment #10
fallcool commentedI followed the steps at #9. An error was received: "Field _links is unknown". I am using Drupal 8.3.2.
Comment #11
moxihang commented@vijaysutar2050 i use you way to creat image file,it success but the file status is temp,not create image file ,and i can't use it at node create.
Comment #12
humPhin commentedsame issue as #11
Comment #13
rob3000 commentedThere is a patch for the File Entity module that will allow the file to be saved permanently here: https://www.drupal.org/node/2756127
Comment #14
garglalit0 commentedhi i am trying to post image from api but the file is not copied it is creating .tmp file i.e file1.tmp something like that my orginal file is not copied to the druapl fo;lder location please help me if anyone has solution
Comment #15
marctty commentedHow procede for private files managed by drupal.
Using this api with private configuration compairs file node with broken attachment. The files on other hand are correctly trasferred to the server web. Have i to add extra parameters to the post?
The instruction for a public configuration run correctly crating a node with accessible file.
Comment #16
yogesh.shukla commentedHi All,
I am implementing react js in front and Drupal as backend, Now Suppose I am creating article type node, I am taking form input, then passing POST type request to drupal and creating article everything is working good, now I want to post image as well for the article with the same request that being sent for article creation, How can send image with rest fields like title, body and so on.
like react code something below:
let config_header = {
headers: {
'Content-Type': 'application/json',
'X-CSRF-Token': 'drW-ozUVkMAroWqk5iqd3aoazC2wYnmKp3TP66jIyRY',
'Authorization': 'Basic YWRtaW46YWRtaW4=',
}
}
const article = {
"type": [
{
"target_id": "article"
}
]
,
"title": [
{
"value":this.state.article_title,
}
],
"body": [
{
"value":this.state.article_body,
}
]
};
above I want to add image field as well with the same request
how can do that
Comment #17
pranav.aeer commentedHi All,
Are there any inputs on #16, please share if any.
Comment #18
stingray commentedFinally, I managed to deliver the file to the server, but then the error 500 rased due destination folder not set. I can't figure where to define this destination directory: in request JSON data or header, or somewhere else in the settings.php or somewhere in REST configuration?
Edited this source core/lib/Drupal/Core/File/FileSystem.php line 488 in order to print the $destination, and it appears to be empty. See '' in the server log below:
Tried to define 'file_private_path' folder in settings.php, added 'tmp' folder under 'sites/default/files' but with no result. What am I missing here?
Comment #19
stingray commentedFound an answer to my question: "destination directory not defined".
You have to specify uri in JSON payload of POST:
Now file deleverd and stored unter /sites/default/files directory
Comment #20
AntonioPC commentedI am trying to insert a image in Drupal from Postman.
The request URL is
http://<urldrupal>/drupal/node?_format=hal_json.The JSON structure inserted in the body is the following.
I get the following error.
I cannot understand what I am doing wrong.
Can anybody help me?
Comment #21
avpaderno@AntonioPC This support request has been closed 5 years ago. Nobody will post an answer here.
Comment #22
Saurabh.123 commented@kiamlaluno how can we get the answer to the question asked by @AntonioPC
As I am facing the same issue. I am getting the following error by running the above API :
Can you at least provide a link so that we can solve this issue?
Comment #23
avpaderno@Saurabh.123 The forums are a better place to ask similar questions.
Comment #24
magendiran commentedThanks @vjsutar,
I have followed the steps #9 in my Drupal 9.5.1 and it is working fine.