Пример #1
0
def add_file(upload, file_name):
    my_user = get_my_user()
    current_directory_object = get_current_directory_object()
    file_id = my_user.key.id() + get_path(file_name, current_directory_object)
    file_key = ndb.Key(File, file_id)

    file_object = File(id=file_id)
    file_object.name = file_name
    file_object.blob = upload.key()
    file_object.put()

    current_directory_object.files.append(file_key)
    current_directory_object.put()
Пример #2
0
def addFile(upload, fileName, fileSize, createdAt):
    my_user = getStoredUser()
    current_Directory = currentDirectory()
    file_id = my_user.key.id() + getPath(fileName, current_Directory)
    file_key = ndb.Key(File, file_id)

    if exists(file_key, current_Directory.files):
        filetoUpload = File(id=file_id)
        filetoUpload.name = fileName
        filetoUpload.size = fileSize
        filetoUpload.createdAt = createdAt
        filetoUpload.blob = upload.key()
        filetoUpload.put()
        current_Directory.files.append(file_key)
        current_Directory.put()

    else:
        blobstore.delete(upload.key())
Пример #3
0
def add_file(upload, file_name):
    my_user = get_my_user()
    current_directory_object = get_current_directory_object()
    file_id = my_user.key.id() + get_path(file_name, current_directory_object)
    file_key = ndb.Key(File, file_id)

    if exists(file_key, current_directory_object.files):
        file_object = File(id=file_id)
        file_object.name = file_name
        file_object.blob = upload.key()
        file_object.put()

        current_directory_object.files.append(file_key)
        current_directory_object.put()

    else:
        # Delete uploaded file from the blobstore
        blobstore.delete(upload.key())
        logging.debug("A file with this name already exists in this directory!")