dehaze

Delete file/folder

You can easily allow users to delete a file or folder via the File Management module of Space Cloud by calling a simple function as shown below:

import { API } from "space-api";

// Initialize api with the project name and url of the space cloud
const api = new API("todo_app", "http://localhost:4122");

// Delete a file
api.FileStore().delete("/some-path/some-file")
  .then(res => {
    if (res.status === 200) {
      // File deleted successfully
    }
    // Error deleting file
  })
  .catch(ex => {
    // Exception occured while processing request
  });

api, err := api.New("books-app", "localhost:4124", false)
if(err != nil) {
  fmt.Println(err)
}
filestore := api.Filestore()
resp, err := filestore.DeleteFile("\\app.txt")
if err != nil {
  fmt.Println("Error:", err)
} else {
  if resp.Status == 200 {
    fmt.Println("Success")
  } else {
    fmt.Println("Error Processing Request:", resp.Error)
  }
}


API api = new API("books-app", "localhost", 4124);
FileStore fileStore = api.fileStore();

fileStore.deleteFile("\\aNewFolder", new Utils.ResponseListener() {
    @Override
    public void onResponse(int statusCode, Response response) {
        if (statusCode == 200) {
            System.out.println("Success");
        } else {
            System.out.println(response.getError());
        }
    }

    @Override
    public void onError(Exception e) {
        System.out.println(e.getMessage());
    }
});

from space_api import API

# Initialize api with the project name and url of the space cloud
api = API("books-app", "localhost:4124")

# Initialize file storage module
file_store = api.file_store()

# Delete a file ("\\a.txt" [remote])
response = file_store.delete_file("\\a.txt")
if response.status == 200:
    print("Success")
else:
    print(response.error)

The delete function takes a path of the file or folder to be deleted.

The delete function will recursively delete all files / folders in a folder if the path was for a folder. The path can be nested as well. For e.g a path - /folder1/folder2/file1 would mean to delete the file - file1 inside folder2 which is in folder1.

Response

A response object sent by the server contains the status fields explained below:

status: Number describing the status of the upload operation. Following values are possible:

  • 200 - Successfully deleted file / folder
  • 401 - Request was unauthenticated
  • 403 - Request was unauthorized
  • 500 - Internal server error

Have a technical question?

Improve the docs!