How to convert a multipart file to File?

You can get the content of a MultipartFile by using the getBytes method and you can write to the file using Files.newOutputStream(): public void write(MultipartFile file, Path dir) { Path filepath = Paths.get(dir.toString(), file.getOriginalFilename()); try (OutputStream os = Files.newOutputStream(filepath)) { os.write(file.getBytes()); } } You can also use the transferTo method: public void multipartFileToFile( MultipartFile multipart, … Read more

how to upload multiple images to a blog post in django

You’ll just need two models. One for the Post and the other would be for the Images. Your image model would have a foreignkey to the Post model: from django.db import models from django.contrib.auth.models import User from django.template.defaultfilters import slugify class Post(models.Model): user = models.ForeignKey(User) title = models.CharField(max_length=128) body = models.CharField(max_length=400) def get_image_filename(instance, filename): title … Read more