Hello,
I am trying to add/upload images with products using API. For that, I guess we need to provide the id of the uploaded image in the API body of the product.

So, I installed module file entity(https://www.drupal.org/project/file_entity). I checked this issue for my solution: https://www.drupal.org/project/drupal/issues/2682341

I am using POSTMAN to run this API.

I am using Drupal 9.2.0

The API I am using to upload image:

URL:
{{Domain}}/entity/file?_format=hal_json

Method: POST

Body:

{
	"_links": {
		"type": {
			"href": "{{Domain}}/rest/type/file/image"
		}
	},
	"filename": [
		{
			"value": "imagename.jpg"
		}
	],
       "filemime": [
		{
		        "value": "image/jpg"
		}
	],
	"data": [
		{
			"value": "base64encoded image string"
		}
	]
}

Response:

{
    "message": "Could not determine entity type bundle: \"type\" field is missing."
}

Any suggestions?

Comments

Saurabh.123 created an issue. See original summary.

Saurabh.123’s picture

Issue summary: View changes
cilefen’s picture

Priority: Major » Normal
Issue tags: -Image upload issues
Saurabh.123’s picture

@cilefen hey, can I also get a solution please, I am stuck in here, need a solution

rsr25694’s picture

@Saurabh.123, hi you should check first how to pass bundle type through api and respectively check whether file path or alternatively id of image while upload test

Saurabh.123’s picture

@rsr25694 I have checked 'how to pass bundle type through API but did not get any useful article as there is no API documentation in Drupal, the best(useful) article I have checked is 'https://www.drupal.org/project/drupal/issues/2682341'.

And I am trying to implement from the same. Can you please give any idea?

Ashish Nandankar’s picture

Please try the below steps

1. Install File Entity module: https://www.drupal.org/project/file_entity
2. Assign administration role to user which is request services with it's basic auth info.

Saurabh.123’s picture

@Ashish Nandakar, I am getting the same error after following the same steps.

{
    "message": "Could not determine entity type bundle: \"type\" field is missing."
}

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.1.10 (June 4, 2021) and Drupal 9.2.10 (November 24, 2021) were the last bugfix releases of those minor version series. Drupal 9 bug reports should be targeted for the 9.3.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

cilefen’s picture

Status: Active » Closed (outdated)

I am closing this support request because there have been no recent comments.

The Drupal Core issue queue is not the ideal place for support requests. Consider other sources of support.