<commit_before>from io import FileIO, BufferedWriter
import os

from django.conf import settings

from ajaxuploader.backends.base import AbstractUploadBackend

class LocalUploadBackend(AbstractUploadBackend):
    UPLOAD_DIR = "uploads"

    def setup(self, filename):
        self._path = os.path.join(
            settings.MEDIA_ROOT, self.UPLOAD_DIR, filename)
        try:
            os.makedirs(os.path.realpath(os.path.dirname(self._path)))
        except:
            pass
        self._dest = BufferedWriter(FileIO(self._path, "w"))

    def upload_chunk(self, chunk):
        self._dest.write(chunk)

    def upload_complete(self, request, filename):
        path = settings.MEDIA_URL + self.UPLOAD_DIR + "/" + filename
        self._dest.close()
        return {"path": path}<commit_msg>use default_storage to save local files<commit_after>import os
from io import FileIO, BufferedWriter


from django.core.files.storage import default_storage
from django.core.files.base import ContentFile
from django.template.loader import render_to_string

from ajaxuploader.backends.base import AbstractUploadBackend


class LocalUploadBackend(AbstractUploadBackend):
    UPLOAD_DIR = 'uploads'

    def setup(self, filename):
        # join UPLOAD_DIR with filename 
        new_path = os.path.join(self.UPLOAD_DIR, filename)

        # save empty file in default storage with path = new_path
        self._path = default_storage.save(new_path, ContentFile(''))

        # get absolute path to new file
        self._abs_path = default_storage.path(self._path)

        # create BufferedWriter for new file
        self._dest = BufferedWriter(FileIO(self._abs_path, "w"))

    def upload_chunk(self, chunk):
        self._dest.write(chunk)

    def upload_complete(self, request, filename):
        self._dest.close()
        return {"path": self._path}
{'fraction_non_alphanumeric': 0.09017278617710583, 'fraction_numerical': 0.0, 'mean_word_length': 3.259770114942529, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5500214', 'n_tokens_mistral': 536, 'n_tokens_neox': 536, 'n_words': 131}