-
Notifications
You must be signed in to change notification settings - Fork 161
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
ImageUrlField is causing an error #287
Comments
It is there so you can also provide an external url so Can you provide the request data as well? |
@tofubit See my question above |
I'm facing the same issue too, I had a working api before adding I'm sending the request image as a form data from my frontend code const formData = new FormData();
const headers = { "Content-Type": "multipart/form-data" };
formData.append("img", blob, file_name);
return await $axios.post(url, formData, { headers }); if I print the
note that I'm also using is there a way to at least disable this override ? @maerteijn if there are any more info you'd like I'd be happy to provide them. |
Can you provide the url you are posting to ( |
I couldn't share the project that I was working on, but I created a minimal project that shows this issue and deployed it on heroku. https://oscar-api-test.herokuapp.com/mapi/store-image/ the project is here if I just remove the line path("api/", include("oscarapi.urls")), from |
the ImageUrlField is there because there is no multipart form-data in a json api. So you can't upload images you have to put a url of an image there, oscarapi will download the image from that url. |
Maybe you are trying to use oscarapi to build a javascript frontend for the admin maybe? In that case you need to implement your own api for uploading images. the admin api is build to synchronise data to oscar from an external application via json/rest. |
@specialunderwear I'm not even trying to use oscar api yet. I currently have an API endpoint that works fine to upload images, just adding oscar api to the project breaks that. in the project that I just linked, if you removed that line from the |
@Jimmar So what you are saying is that by just installing / enabling |
basically yes, doesn't to work well with formData, the serializer is expecting if you take a look at this comment that I wrote here it has a link to a sample project that I made to showcase this issue and a url to test it (deployed on Heroku) |
Ok confirmed, This is because we patch rest framework to have the def expand_field_mapping(extra_fields):
# This doesn't make a copy
field_mapping = serializers.ModelSerializer.serializer_field_mapping # <-- monkeypaych
field_mapping.update(extra_fields)
return field_mapping
class OscarSerializer(object):
field_mapping = expand_field_mapping(
{
oscar.models.fields.NullCharField: serializers.CharField,
models.ImageField: ImageUrlField,
}
) This, of course, we shouldn't do. Fastest solution for now: explicity define the DRF ImageField on the serializer while we think of a solution. |
when I try to create a category with an image I get the following error:
can someone also tell me what is the purpose of this ImageUrlField and why it replaces the rest_frameworks ImageField?
The text was updated successfully, but these errors were encountered: