Django/ Cannot upload image to server

I just started with Django and server programming, is there any thing I should know, please kindly give advise.

Question: I am trying to upload image to the server. I received Imagename (string) and Imagefile (multipart) from android, Imagename is successfully saved with below algorithm but Imagefile wasn't. What did I do wrong?

Here is the code below,

def Createtest(request):
if request.method == "POST":        
    serializer = FullSerializer(request.POST, request.FILES)
    if serializer.is_valid():
        return JsonResponse({'code':'0000', 'msg': 'saved'}, status=200)
    return JsonResponse({'code':'1001', 'msg': 'failed'}, status=200)

class FullSerializer(forms.ModelForm):
   class Meta:
        model = Character
        fields = ('imgname','imgfigure')

class Character(models.Model):
   imgname = models.TextField(max_length=20)
   imgfigure = models.ImageField(upload_to='Image/',blank=True, null=True)

Here is the request data in Django

//The result of request.POST = <QueryDict: {'imgname': ['"session1"']}>
//The result of request.FILES = <MultiValueDict: {'character': [<InMemoryUploadedFile: haruRoll.jpg (image/*)>]}>

Here is Retrofit service from Kotlin

interface SessionCreateService {
   @POST ("/character/create/")
   fun SessCreate(
      @Part("imgname") imgname:String,
      @Part imgfigure : MultipartBody.Part,
   ):Call<SessionCreate_o> //output
Back to Top