BOX: How to download file using file url? - box-api

I want to use Box SDK to download a file. I have the file link available in local variable
var url = https://mycompany.box.com/s/c565vhytyhx5s85vjg03bgtr0h47d6nh
Currently BoxClient.FilesManager.DownloadStreamAsync(fileid) takes fileid as parameter.
How do I use url to download a file from box using Box SDK?

Use following Code to Download File From Box using box api
BoxFile file=new BoxFile(api, fileID);
FileOutputStream fOut = new FileOutputStream(file path);
URL DownloadUrl=file.getDownloadURL();
BufferedInputStream input=new BufferedInputStream(DownloadUrl.openStream());
and write above file "input" to FileOutputStream with file path where u want

Related

Difference in size of HTML file directly downloaded from Google Drive and via Drive API

I uploaded a word document on Google Drive. I am downloading the file in HTML format in following two ways.
First method: I open the file in Google Docs and then downloaded the file: File -> Download as -> Web page (.html, zipped). I unzip the tar and then I get the HTML file. Its size is 62 kB.
Second method: I used Drive API v3 to create (or upload) the word document to Google Drive. Then I exported the file to HTML format. Its size is 173 kB.
My question is why there is difference of almost three times in size of HTML file? What should be done to get the same file size (62 kB) when downloading (or exporting) using Drive API?
This is the Drive API code I am using to create and export the file.
Drive service = getDriveService();
File fileMetadata = new File();
fileMetadata.setName("Test Document");
fileMetadata.setMimeType("application/vnd.google-apps.document");
FileContent fileContent = new FileContent("application/vnd.openxmlformats-officedocument.wordprocessingml.document", new java.io.File("/home/test/test.doc"));
File createResponse = service.files().create(fileMetadata, fileContent).execute();
java.io.File parentDir = new java.io.File("/home/test/");
if (!parentDir.exists()) {
throw new IOException("Parent directory does not exists.");
}
OutputStream out = new FileOutputStream(new java.io.File(parentDir, "Test Document"));
service.files().export(createResponse.getId(), "text/html").executeAndDownloadTo(out);
Kindly help me with this issue.
Thanks.

How To Open PDFdocument Through Windows Phone 8 App Which Is From Asset Folder

I need to open a pdf document file from the asset folder from windows phone 8 app. First I need to check whether any pdf reader is available or not and if available, the pdf document should be opened from the asset folder.
There are two ways of using a file. You can mark it as
Resource Files: Data files that are compiled into either an executable or library assembly. To access a resource,
Example :
Stream jsStream = Application.GetResourceStream(new Uri("folder\\e_data.pdf",UriKind.Relative)).Stream;
Content Files: Standalone data files that have an explicit association with an executable assembly.
To access content file, use
Uri filePath = new Uri(#"ms-appx:///example.pdf");
StorageFile file = await StorageFile.GetFileFromApplicationUriAsync();
EXAMPLE
Mark the pdf file as content in properties -> build action.
async void openPDF()
{
Uri filePath = new Uri(#"ms-appx:///example.pdf");
StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(filePath);
//For opening that file,
if (file != null)
await Launcher.LaunchFileAsync(file);
}

how to get browsed file location by user when he wants to download a file

this is my html code to make user to download a file and it is hitting controller
window.location.href="#routes.ListManagementController.downloadList("+listName+")?listname="+listName;
this is my controller code:
String listName = Form.form().bindFromRequest().get("listname");
response().setContentType("application/x-download");
response().setHeader("Content-disposition", "attachment;filename="+listName+"_data_export.csv");
The above two respose() statements make a pop up to download a file I want the browsed file location
File file = new File("C:/csv/" + filename);
So, using servlet api we can write the content into browsed file location using respose.getOutputStream() method. In play there are is no support for servlet. I want browsed file location selected by user so that i can give that location to File and write the file over there.
You can't get the location of a directory on the client, and even if you could, your server side could wouldn't be able to write to it (since it would usually be on a different computer).

The uploaded files are not converted to Google Documents

I use Google Drive API to upload new files (https://developers.google.com/drive/v2/reference/files/insert), and I use the 'convert' parameter to convert the file in Google Document.
It worked well but today, the uploaded files are not converted.
I tried with a .doc, .docx and .ppt, and I have the same problem.
Does anyone has an idea? Is the API has been changed?
Make sure you are using the correct mime type. See code below.
Drive driveService = new Drive.Builder(...).setApplicationName(...).build();
File fileMetadata = new File();
fileMetadata.setName("file1.doc");
fileMetadata.setMimeType("application/vnd.google-apps.document");
AbstractInputStreamContent inputStream = new InputStreamContent(null,
new FileInputStream(new java.io.File("/file1.doc")));
File file = driveService.files().create(fileMetadata, in).setFields("id").execute();

Download files from folder with webmatrix

I have a folder created to get the files that users upload. However when i try to download the files, some extensions don't download.
I have this code to list all files that are in the folder, i can see all the files with no problem.
#foreach (string fullFilePath in Directory.GetFiles(Path.Combine(Server.MapPath("~/uploadedFiles"),"Ticket Id - "+#id)))
{
<div class="linkFicheiros">#Path.GetFileName(fullFilePath)</div>
}
With this line
#Path.GetFileName(fullFilePath)
i can download files with extension: ".zip" , ".xls" but extensions like ".msg"(sometimes users need to upload this extension) i got an error "The page cannot be found". Even ".jpg" instead of downloading the file it opens the image on the browser.
I think that is something how i'm trying to reach the file, but i can't get to a solution.
Any thoughts ?
The browser would try to always view the content of the file. If its an Image file like .jng etc. But if there is a .zip file, it would let the user download and open it. Because browser can't open it.
You need to push the file to the user. For that you can try the following code:
var file = Server.MapPath("~/images/" + Request["img"]);
Response.AppendHeader(
"content-disposition", "attachment; filename=" +
Request["img"]);
Response.ContentType = "application/octet-stream";
Response.TransmitFile(file);
Now, you can see that in the code I am sharing, the file is a variable, which is being pointed to the file in the File System. Please note that there is a Query String parameter, which would be sent alongwith the URL, for example:
Download Image
Now the header would be appened, and the
Request.ContentType = "application/octet-stream"
is used to force the browser to show the Dialoug of Open/Save.
Then the transmit file to download it.
To only execute the code when needed
To only execute that download code block, you need to set the value in a block for condition to be true. For example, you can use a parameter to check whether to download the file or not. Try something simple like,
<a href="~/download_file/image_link.png?download=true>Download</a>
Then on the code behind use this:
var download = Request.QueryString["download"];
if(download == "true") {
/* place the code here */
}
Now it would only execute if the condition is true, otherwise it would skip that part.