Join() argument must be str or bytes, not 'PngImageFile'

What I’m trying to do is taking an image from the user as input and trying to save it on a server that is on my pc.

I have converted the Media object into bytes but getting this error while saving
image

Here is my Python Code:

import os
from PIL import Image
import io
import cv2
import anvil.media

@anvil.server.callable


def filesup1(img):
    path = r"E:\project"
    file1 = Image.open(io.BytesIO(img.get_bytes()))
    compath = os.path.join(path,file1)
    print(file1)
    file1.save(compath,'png')



Clone link:
https://anvil.works/build#clone:G53OKFTQC5IXSI2L=CLWMLCDVZHHFMDLS25PZ5GEXWhat

You may be over-complicating things. Compare this to the error message.

I tried this but now I’m getting this error:
image

My apologies. I should have read more closely.

I see that you want to compute a full filename, with path, using os.path.join. The first parameter to os.path.join is the name of a folder. For this to work, the 2nd parameter will need to be a string, containing the name of the file, within that folder, that you want to create.

What filename do you want to use?

No Problem :blush:

What I was trying to do is to save the user images on my pc(server) so I tried to convert the input image and save it in file1. I used os.path.join to save converted images into my pc folder.
Here maybe I am using the wrong concept because I can’t think of any other way to save user images on my pc. If there is a way please guide it would be helpful.

In this case, you can imagine that there are two parts of saving a file:

  1. Knowing where to save it (i.e., what path and file name to use).
  2. Knowing how to save it.

Usually, your program needs to figure these out in this order. Which is why I asked about #1. If you don’t have a name for the file, then the rest of it is not going to work.

So let’s finish with #1. What name do you want to use? Once you know that, then we can work on making your code apply that information.