use of com.dropbox.core.v2.DbxPathV2 in project dropbox-sdk-java by dropbox.
the class DropboxBrowse method doBrowse.
// -------------------------------------------------------------------------------------------
// GET /browse?path=...
// -------------------------------------------------------------------------------------------
// The page that lets you browse your Dropbox account. Makes Dropbox API calls to figure out
// the contents of your files and folders and display them to you.
public void doBrowse(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
if (!common.checkGet(request, response))
return;
User user = common.getLoggedInUser(request);
if (user == null) {
common.pageSoftError(response, "Can't do /browse. Nobody is logged in.");
return;
}
DbxClientV2 dbxClient = requireDbxClient(request, response, user);
if (dbxClient == null)
return;
String path = request.getParameter("path");
if (path == null || path.length() == 0) {
renderFolder(response, user, dbxClient, "");
} else {
String pathError = DbxPathV2.findError(path);
if (pathError != null) {
response.sendError(400, "Invalid path: " + jq(path) + ": " + pathError);
return;
}
Metadata metadata;
try {
metadata = dbxClient.files().getMetadata(path);
} catch (GetMetadataErrorException ex) {
if (ex.errorValue.isPath()) {
LookupError le = ex.errorValue.getPathValue();
if (le.isNotFound()) {
response.sendError(400, "Path doesn't exist on Dropbox: " + jq(path));
return;
}
}
common.handleException(response, ex, "getMetadata(" + jq(path) + ")");
return;
} catch (DbxException ex) {
common.handleDbxException(response, user, ex, "getMetadata(" + jq(path) + ")");
return;
}
path = DbxPathV2.getParent(path) + "/" + metadata.getName();
if (metadata instanceof FolderMetadata) {
renderFolder(response, user, dbxClient, path);
} else {
renderFile(response, path, (FileMetadata) metadata);
}
}
}
use of com.dropbox.core.v2.DbxPathV2 in project dropbox-sdk-java by dropbox.
the class Main method main.
public static void main(String[] args) throws IOException {
// Only display important log messages.
Logger.getLogger("").setLevel(Level.WARNING);
if (args.length != 3) {
System.out.println("");
System.out.println("Usage: COMMAND <auth-file> <local-path> <dropbox-path>");
System.out.println("");
System.out.println(" <auth-file>: An \"auth file\" that contains the information necessary to make");
System.out.println(" an authorized Dropbox API request. Generate this file using the \"authorize\"");
System.out.println(" example program.");
System.out.println("");
System.out.println(" <local-path>: The path to a local file whose contents you want to upload.");
System.out.println("");
System.out.println(" <dropbox-path>: The path on Dropbox to save the file to.");
System.out.println("");
System.exit(1);
return;
}
String argAuthFile = args[0];
String localPath = args[1];
String dropboxPath = args[2];
// Read auth info file.
DbxAuthInfo authInfo;
try {
authInfo = DbxAuthInfo.Reader.readFromFile(argAuthFile);
} catch (JsonReader.FileLoadException ex) {
System.err.println("Error loading <auth-file>: " + ex.getMessage());
System.exit(1);
return;
}
String pathError = DbxPathV2.findError(dropboxPath);
if (pathError != null) {
System.err.println("Invalid <dropbox-path>: " + pathError);
System.exit(1);
return;
}
File localFile = new File(localPath);
if (!localFile.exists()) {
System.err.println("Invalid <local-path>: file does not exist.");
System.exit(1);
return;
}
if (!localFile.isFile()) {
System.err.println("Invalid <local-path>: not a file.");
System.exit(1);
return;
}
// Create a DbxClientV2, which is what you use to make API calls.
DbxRequestConfig requestConfig = new DbxRequestConfig("examples-upload-file");
DbxClientV2 dbxClient = new DbxClientV2(requestConfig, authInfo.getAccessToken(), authInfo.getHost());
// deciding factor. This should really depend on your network.
if (localFile.length() <= (2 * CHUNKED_UPLOAD_CHUNK_SIZE)) {
uploadFile(dbxClient, localFile, dropboxPath);
} else {
chunkedUploadFile(dbxClient, localFile, dropboxPath);
}
System.exit(0);
}
Aggregations