How to send image files to NAS server in my application? - java

I want to send image files (jpg, png) to NAS server in java using smb
I have added the jcifs-1.3.19.jar. as mentioned here and here
Edit: I have successfully sent jpeg image to a shared folder on server using this code, but the speed is very slow, its sending almost 1kb/second. Any Solution??
static final String USER_NAME = "Waqas";
static final String PASSWORD = "mypass";
static final String NETWORK_FOLDER = "smb://DESKTOP-LAP/Users/Waqas/";
public boolean copyFiles(FileInputStream file, String fileName) {
boolean successful = false;
int cursor;
SmbFileOutputStream sfos;
SmbFile sFile;
String path;
NtlmPasswordAuthentication auth;
try{
String user = USER_NAME + ":" + PASSWORD;
auth = new NtlmPasswordAuthentication(user);
StrictMode.ThreadPolicy tp = StrictMode.ThreadPolicy.LAX; StrictMode.setThreadPolicy(tp);
path = NETWORK_FOLDER + fileName;
sFile = new SmbFile(path, auth);
sfos = new SmbFileOutputStream(sFile);
while((cursor = file.read())!=-1){
sfos.write(cursor);
}
successful = true;
System.out.println("Successful " + successful);
}
catch (Exception e) {
successful = false;
e.printStackTrace();
}
return successful;
}

Finally here is the solution:
public boolean copyFiles(FileInputStream file, String fileName) {
boolean successful = false;
int cursor;
SmbFileOutputStream sfos;
SmbFile sFile;
String path;
NtlmPasswordAuthentication auth;
try{
String user = USER_NAME + ":" + PASSWORD;
System.out.println("User: " + user);
auth = new NtlmPasswordAuthentication(user);
StrictMode.ThreadPolicy tp = StrictMode.ThreadPolicy.LAX; StrictMode.setThreadPolicy(tp);
path = NETWORK_FOLDER + fileName+".jpeg";
System.out.println("Path: " +path);
sFile = new SmbFile(path, auth);
sfos = new SmbFileOutputStream(sFile);
long t0 = System.currentTimeMillis();
byte[] b = new byte[8192];
int n, tot = 0;
Log.d("asdf","initiating : total="+tot);
while((n = file.read(b))>0){
sfos.write( b, 0, n );
tot += n;
Log.d("asdf","writing : total="+tot);
}
successful = true;
Log.d("asdf","Successful : total="+tot);
}
catch (Exception e) {
successful = false;
e.printStackTrace();
Log.d("asdf","exxeption ");
}
return successful;
}

Related

Executing a java class in Eclipse

I have a java project in Eclipse which was written by some other developer. I am very new to Java and have made some modifications in the source code. Now i want to test the code by executing it in eclipse. How can I create a main class and execute the modified code.
Following is the class file which I want to run
public class Bio_Verify extends AbstractOutboundServiceProvider
{
public static String EndPointURL = null;
public static String ApiKey = null;
public static String Version = null;
public static String EntityId = null;
public static String requestId = null;
public static String EncryptionKey = null;
public static String SignatureKey = null;
public static String SignAlgorithm = null;
public String requestData = null;
public String requestXML = null;
public String response = null;;
public String errorMsg;
public void preprocess(IUsbMessage inputMsg)
{
LogManager.logDebug("Bio_Verify: preprocess():: inside preprocess");
LogManager.logDebug("Bio_Verify: executeOutboundRequest():: START");
}
public IUsbMessage executeOutboundRequest(String inputMsg)
{
int i = 0;
int j = 0;
String resolution = null;
String key = null;
String criteria = null;
String position = null;
String format = null;
String data = null;
String intent = null;
String resBodyXML = null;
String outputXMLMsg = null;
String[] responseMsg = new String[2];
IUsbMessage outMsg = null;
Verify verify = new Verify();
Fingerprint fingerprint = new Fingerprint();
requestData = "CN01473|cif|UNKNOWN_FINGER|508|BMP|Qk12WeoAAAA=|verify";
//Forming requestId for Bio
Date date = Calendar.getInstance().getTime();
DateFormat dateFormat = new SimpleDateFormat("yyyymmddhhmmss");
requestId = dateFormat.format(date);
EndPointURL = OutboundConstants.Bio_Endpoint;
ApiKey = OutboundConstants.ApiKey;
Version = OutboundConstants.Version;
EntityId = OutboundConstants.EntityId;
EncryptionKey = OutboundConstants.EncryptionKey;
SignAlgorithm = OutboundConstants.SignAlgorithm;
SignatureKey = OutboundConstants.SignatureKey;
LogManager.logDebug("Bio_Verify: executeOutboundRequest():: Bio_Endpoint URL is " + EndPointURL);
LogManager.logDebug("Bio_Verify: executeOutboundRequest():: Api Key is " + ApiKey);
LogManager.logDebug("Bio_Verify: executeOutboundRequest():: Version is " + Version);
LogManager.logDebug("Bio_Verify: executeOutboundRequest():: EntityId is " + EntityId);
LogManager.logDebug("Bio_Verify: executeOutboundRequest():: EncryptionKey is " + EncryptionKey);
LogManager.logDebug("Bio_Verify: executeOutboundRequest():: SignatureKey is " + SignatureKey);
LogManager.logDebug("Bio_Verify: executeOutboundRequest():: SignAlgorithm is " + SignAlgorithm);
LogManager.logDebug("Bio_Verify: executeOutboundRequest():: Request Id is " + requestId);
//Extraction data from the request XML
for(i=0;i<7;i++){
int x = requestData.indexOf("|");
int y = requestData.length();
if(i==0){
key = requestData.substring(0, x);
LogManager.logDebug("Key: "+key);
requestData = requestData.substring(x+1,y);
}
if(i==1){
criteria = requestData.substring(0, x);
LogManager.logDebug("Criteria: "+criteria);
requestData = requestData.substring(x+1,y);
}
if(i==2){
position = requestData.substring(0, x);
LogManager.logDebug("Position: "+position);
requestData = requestData.substring(x+1,y);
}
if(i==3){
format = requestData.substring(0, x);
LogManager.logDebug("Format: "+format);
requestData = requestData.substring(x+1,y);
}
if(i==4){
resolution = requestData.substring(0, x);
LogManager.logDebug("Resolution: "+resolution);
requestData = requestData.substring(x+1,y);
}
if(i==5){
data = requestData.substring(0, x);
requestData = requestData.substring(x+1,y);
}
if(i==6){
intent = requestData;
LogManager.logDebug("Intent: "+intent);
}
}
FingerprintImage fingerprintimage = new FingerprintImage(format,resolution,data);
fingerprint.image = fingerprintimage;
fingerprint.position = position;
responseMsg = verify.verify(key, criteria, fingerprint, intent);
this.errorMsg = responseMsg[0];
this.response = responseMsg[1];
LogManager.logDebug("Back in bio verify - array element1"+this.errorMsg);
LogManager.logDebug("Back in bio verify - array element2"+this.response);
outMsg = UsbMessageFactory.createUbusMessage();
outMsg.setMsgType("XML");
outMsg.setMsgSubType("FIXML");
LogManager.logDebug("Bio: executeOutboundRequest():: errorMsg=" + errorMsg);
if (errorMsg.toString().trim().length() > 0)
{
LogManager.logDebug("Bio_Verify: executeOutboundRequest():: Inside FAILURE");
outMsg.setBackEndTranStatus("FAILURE");
outMsg.setErrMsgFlg(1);
outMsg.setPayload(new Object[] { new CIFatalException(errorMsg.toString()) });
}
else
{
LogManager.logDebug("Bio_Verify: executeOutboundRequest():: Inside SUCCESS");
outMsg.setBackEndTranStatus("SUCCESS");
outMsg.setErrMsgFlg(0);
resBodyXML = this.response.toString();
LogManager.logDebug("Bio_Verify: executeOutboundRequest():: outputXMLMsg XML:" + outputXMLMsg);
outMsg.setPayload(new Object[] { outputXMLMsg });
}
LogManager.logDebug("Bio_Verify: executeOutboundRequest():: outMsg:" + outMsg);
LogManager.logDebug("Bio_Verify: executeOutboundRequest():: END");
return outMsg;
}
Can you follow the steps , this will help to you
There are 6 steps are below added ( I think you will get idea how to archive your problem )
1.Right click inside package and you can see CLASS then it will pop up this attached window
2. Insight Main method you can crate some object like I have created and pass parameter what you want (You just understand what method you have to call )
You have to write main function into Bio_Verify class.
main function is boot function.
So if you write main function, you can execute this class.
ex)
public class BioVerify extends AbstractOutboundServiceProvider {
public static void main(String[] args) {
// TODO: Write a code....
}
}
write the main function below to the code and create object for BIO_verify class and it's function

Upload document on google drive in a folder

I want to upload my document on google drive but in a folder. can you please suggest how i insert this into the folder. I have uploaded but this is not in folder. Code is -
#RequestMapping(value = "/uploadDDFile", method = RequestMethod.POST)
public ModelAndView uploadDDFile(#RequestParam(value = "ddid", required = true) Integer ddid,
#RequestParam(value = "catageryId", required = true) Integer catageryId,
#RequestParam(value = "document", required = true) GMultipartFile document[], HttpServletRequest request) {
System.out.println("-------------------------");
String name = "";
DdeDriveDocuments ddeDriveDocuments = new DdeDriveDocuments();
if (ServletFileUpload.isMultipartContent(request) && document != null) {
for (GMultipartFile gdocument : document) {
try {
boolean user = true;
List<DdeDriveDocuments> dds = ddeDriveDocumentsService.fatchData(ddid, catageryId);
for (DdeDriveDocuments file : dds) {
System.out.println(file.getDocument_name());
if (file.getDocument_name().equals(gdocument.getOriginalFilename())) {
user = false;
}
}
if (user == true) {
Client client = sessionService.getClient();
System.out.println(gdocument.getOriginalFilename());
ddeDriveDocuments
.setDocument_name((gdocument.getName() != null ? gdocument.getOriginalFilename() : ""));
ddeDriveDocuments.setDocument_uploadby(client.getEmail());
ddeDriveDocuments.setDocument_created(new Date());
ddeDriveDocuments.setCatagery_id(catageryId);
ddeDriveDocuments.setDd_id(ddid);
ddeDriveDocuments.setDd_uuid(GeneralUtil.getUUID());
ddeDriveDocuments.setClientID(client.getClientID());
Lawyer googleAuthToken = lawyerService
.getAuthorisedUserToken(Configurator.getInstance().getDriveAccountEmail());
if (googleAuthToken != null) {
// upload file in drive
if (ServletFileUpload.isMultipartContent(request) && document != null) {
// It's value either we need to get from form.
String description = "Testing";
File file = DriveService.uploadDocumentToDrive(googleAuthToken, gdocument,
ddeDriveDocuments.getDocument_name(), description);
File thumFile = DriveService.getFileById(googleAuthToken, file.getId());
System.out.println("thumFile ====" + thumFile);
System.out.println("thab url" + thumFile.getIconLink());
if (file != null) {
ddeDriveDocuments.setDocument_drive_id(file.getId());
ddeDriveDocuments.setImageurl(thumFile.getIconLink());
ddeDriveDocuments = ddeDriveDocumentsService.create(ddeDriveDocuments);
}
}
} else {
System.out.println("Autorised token not available for configured drive account.");
}
} else {
System.out.println("wroung Input");
System.out.println("wroung Input");
name = name.concat(gdocument.getOriginalFilename() + " , ");
System.out.println("This is ::::::::::::: " + name);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
if(name !=""){
sessionService.setUnupload_files_name(name);
}
return new ModelAndView("redirect:/al/client/ddeclientportal/" + ddid + "/" + catageryId);
}
public static File uploadDocumentToDrive(Lawyer googleAuthToken,
GMultipartFile file, String fileName, String description) {
File driveFile = null;
try {
InputStream fileStream = file.getInputStream();
String mimeType = DocumentListEntry.MediaType.fromFileName(
file.getOriginalFilename()).getMimeType();
GoogleCredential googleCrednetial = getGoogleCredential(googleAuthToken);
Drive drive = buildService(googleCrednetial);
String file_name = fileName.contains(FilenameUtils.getExtension(file.getOriginalFilename())) ? fileName : fileName + "." + FilenameUtils.getExtension(file.getOriginalFilename());
File body1 = new File();
body1.setTitle("cloudbox");
body1.setMimeType("application/vnd.google-apps.folder");
driveFile = drive.files().insert(body1).execute();
File body = new File();
body.setTitle(file_name);
body.setDescription(description);
body.setMimeType(mimeType);
driveFile = drive.files()
.insert(body, new InputStreamContent(mimeType, fileStream))
.execute();
} catch (Exception e) {
e.printStackTrace();
}
return driveFile;
}
Please help i want insert my document in folder.
By Using
File body1 = new File();
body1.setTitle("cloudbox");
body1.setMimeType("application/vnd.google-apps.folder");
driveFile = drive.files().insert(body1).execute();
File body = new File();
body.setTitle(file_name);
body.setDescription(description);
body.setMimeType(mimeType);
body.setParents(Arrays.asList(new ParentReference().setId(driveFile.getId())));
driveFile = drive.files()
.insert(body, new InputStreamContent(mimeType, fileStream))
.execute();
Now can you please suggest how i can generate subfoler.

How to use apache vfs2 for sftp with public-private-key and without password

Currently I am using apache vfs2 to download files from a sftp. For authentication I use user-name and password.
Is there a way to use vfs2 only with public-private-keys and without a password?
I think I have use this function,but how? Set it only to "yes"?
SftpFileSystemConfigBuilder.getInstance().setStrictHostKeyChecking(options, "no");
This is my current code (snippet):
private boolean downloadFile(){
StandardFileSystemManager sysManager = new StandardFileSystemManager();
//download der Datei
try {
sysManager.init();
FileObject localFile = sysManager.resolveFile(localFilePath);
FileObject remoteFile = sysManager.resolveFile(createConnectionString(host, user, password, fileName, port),createDefaultOptions());
//Selectors.SELECT_FILES --> A FileSelector that selects only the base file/folder.
localFile.copyFrom(remoteFile, Selectors.SELECT_FILES);
} catch (Exception e) {
logger.error("Downloading file failed: " + e.toString());
return false;
}finally{
sysManager.close();
}
return true;
}
and
private FileSystemOptions createDefaultOptions() throws FileSystemException{
//create options for sftp
FileSystemOptions options = new FileSystemOptions();
//ssh key
SftpFileSystemConfigBuilder.getInstance().setStrictHostKeyChecking(options, "no");
//set root directory to user home
SftpFileSystemConfigBuilder.getInstance().setUserDirIsRoot(options, true);
//timeout
SftpFileSystemConfigBuilder.getInstance().setTimeout(options, timeout);
return options;
}
Taking your code and wrapping it into a runnable example. Notice the IdentityInfo implementation. This can work with a key-with-passphrase by changing the obvious lines.
$ javac -cp 'jsch-0.1.51.jar;commons-vfs2-2.0.jar' SftpGet.java
$ java -cp 'jsch-0.1.51.jar;commons-vfs2-2.0.jar;commons-logging-1.1.1.jar;.' SftpGet
with
import java.io.File;
import com.jcraft.jsch.UserInfo;
import org.apache.commons.vfs2.FileObject;
import org.apache.commons.vfs2.FileSystemException;
import org.apache.commons.vfs2.FileSystemManager;
import org.apache.commons.vfs2.FileSystemOptions;
import org.apache.commons.vfs2.Selectors;
import org.apache.commons.vfs2.impl.StandardFileSystemManager;
import org.apache.commons.vfs2.provider.sftp.SftpFileSystemConfigBuilder;
import org.apache.commons.vfs2.provider.sftp.IdentityInfo;
public class SftpGet {
public static void main(String[] args) {
downloadFile();
}
private static boolean downloadFile(){
String host = "HOSTNAMEHERE";
String user = "USERNAMEHERE";
String password = "";
String fileName = "/lines.txt";
String localFilePath = "c:/cygwin64/home/woddle/wrote_lines.txt";
// without passphrase
String keyPath = "c:/cygwin64/home/woddle/.ssh/id_dsa_nopass";
String passphrase = null;
// with passphrase
// String keyPath = "c:/cygwin64/home/woddle/.ssh/id_dsa_withpass";
// String passphrase = "super-secrets";
StandardFileSystemManager sysManager = new StandardFileSystemManager();
//download der Datei
try {
sysManager.init();
FileObject localFile = sysManager.resolveFile(localFilePath);
FileObject remoteFile = sysManager.resolveFile(createConnectionString(host, user, password, keyPath, passphrase, fileName), createDefaultOptions(keyPath, passphrase));
//Selectors.SELECT_FILES --> A FileSelector that selects only the base file/folder.
localFile.copyFrom(remoteFile, Selectors.SELECT_FILES);
} catch (Exception e) {
System.out.println("Downloading file failed: " + e.toString());
return false;
}finally{
sysManager.close();
}
return true;
}
public static String createConnectionString(String hostName, String username, String password, String keyPath, String passphrase, String remoteFilePath) {
if (keyPath != null) {
return "sftp://" + username + "#" + hostName + "/" + remoteFilePath;
} else {
return "sftp://" + username + ":" + password + "#" + hostName + "/" + remoteFilePath;
}
}
private static FileSystemOptions createDefaultOptions(final String keyPath, final String passphrase) throws FileSystemException{
//create options for sftp
FileSystemOptions options = new FileSystemOptions();
//ssh key
SftpFileSystemConfigBuilder.getInstance().setStrictHostKeyChecking(options, "no");
//set root directory to user home
SftpFileSystemConfigBuilder.getInstance().setUserDirIsRoot(options, true);
//timeout
SftpFileSystemConfigBuilder.getInstance().setTimeout(options, 10000);
if (keyPath != null) {
IdentityInfo identityInfo = null;
if(passPhrase!=null){
identityInfo = new IdentityInfo(new File(keyPath), passPhrase.getBytes());
}else{
identityInfo = new IdentityInfo(new File(keyPath));
}
SftpFileSystemConfigBuilder.getInstance().setIdentityInfo(options, identityInfo);
}
return options;
}
}
We should not use below method for creating the connection string. This may expose the password.
public static String createConnectionString(String hostName, String username, String password, String keyPath, String passphrase, String remoteFilePath) {
if (keyPath != null) {
return "sftp://" + username + "#" + hostName + "/" + remoteFilePath;
} else {
return "sftp://" + username + ":" + password + "#" + hostName + "/" + remoteFilePath;
}
}
As per the documentation available on the Apache website, we should use
StaticUserAuthenticator auth = new StaticUserAuthenticator("domain", "username", "password");
Link: https://commons.apache.org/proper/commons-vfs/api.html
Also, if we are using public key or private key based authentication, then we should use setIdentityInfo(FileSystemOptions, IdentityInfo...) instead of setIdentities(FileSystemOptions opts, File... identityFiles).
Reference: https://commons.apache.org/proper/commons-vfs/commons-vfs2/apidocs/org/apache/commons/vfs2/provider/sftp/SftpFileSystemConfigBuilder.html
FileSystemOptions opts = new FileSystemOptions();
SftpFileSystemConfigBuilder.getInstance().setStrictHostKeyChecking(opts, "no");
SftpFileSystemConfigBuilder.getInstance().setUserDirIsRoot(opts, false);
String openSSHPrivateKey = "C:\\Users\\<filepath>\\id_rsa.key";
IdentityInfo myIdentityInfo = new IdentityInfo(new File(openSSHPrivateKey));
SftpFileSystemConfigBuilder.getInstance(). setIdentityInfo(opts, myIdentityInfo);

Java: How to download a file via imap:// protocol?

How can I download a file given the following URL with Java-SE-7:
imap://georg#imap.acme.com:143/fetch%3EUID%3E/INBOX%3E18678?fileName=testmail.eml
Any help highly appreciated - thank you in advance.
Here's my basic solution. The following code needs Apache Commons I/O 2.4 which can be downloaded here:
public class ImapMessage {
private String authority;
private String protocol;
private String host;
private int port;
private String username;
private String password;
private String foldername;
private long msgid;
private String filename;
private Message message;
public ImapMessage(String url) throws IOException, MessagingException {
parseURL(decodeURL(url));
}
#Override
public String toString() {
return "protocol: "+protocol+"\n"+
"host: "+host+"\n"+
"port: "+port+"\n"+
"username: "+username+"\n"+
"password: "+password+"\n"+
"folder: "+foldername+"\n"+
"msgid: "+msgid+"\n"+
"filename: "+filename;
}
private String decodeURL(String url) throws IOException {
if(url!=null && !url.isEmpty()) {
url = StringUtils.replace(url, "%3E", ">");
url = StringUtils.replace(url, "%20", " ");
return url;
} else {
throw new IOException("The given URL is empty or invalid.");
}
}
private void parseURL(String url) throws IOException, MalformedURLException {
if(url!=null && !url.isEmpty()) {
//<editor-fold defaultstate="collapsed" desc="Parse Protocol">
if(url.startsWith("imaps")) {
url = StringUtils.replace(url, "imaps", "http", 1);
protocol = "imaps";
} else if(url.startsWith("imap")) {
url = StringUtils.replace(url, "imap", "http", 1);
protocol = "imap";
} else {
throw new IOException("Unsupported protocol: "+url.substring(0, url.indexOf("://")));
}
try {
URL newurl = new URL(url);
String path = newurl.getPath();
String query = newurl.getQuery();
authority = newurl.getAuthority();
host = newurl.getHost();
port = newurl.getPort();
username = newurl.getUserInfo();
password = "provide your password here";
foldername = path.substring(path.indexOf(">/")+2, path.lastIndexOf(">"));
msgid = Long.parseLong(path.substring(path.lastIndexOf(">")+1, path.length()));
filename = query.substring(query.indexOf("=")+1, query.length());
} catch (MalformedURLException ex) {
throw ex;
}
} else {
throw new IOException("The given URL is empty or invalid.");
}
}
public File fetchMessage() throws IOException, FileNotFoundException, MessagingException {
Store store = null;
Folder folder = null;
File filepath = new File("/destination/directory");
try {
Properties props = System.getProperties();
props.setProperty("mail.store.protocol", protocol);
Session session = Session.getDefaultInstance(props, null);
// session.setDebug(true);
store = session.getStore(protocol);
store.connect(host, port, username, password);
folder = store.getFolder(foldername);
folder.open(Folder.READ_ONLY);
UIDFolder ufolder = (UIDFolder)folder;
message = ufolder.getMessageByUID(msgid);
if(message!=null) {
File file = null;
if(filename.equals("null")) {
file = new File(filepath.getAbsolutePath()+File.separator+Long.toString(System.nanoTime())+".eml");
} else {
file = new File(filepath.getAbsolutePath()+File.separator+filename);
}
message.writeTo(new FileOutputStream(file));
return file;
} else {
throw new MessagingException("The requested e-mail could not be found on the mail server.");
}
} catch(Exception ex) {
throw ex;
} finally {
if(folder!=null) {
folder.close(true);
}
if(store!=null) {
store.close();
}
}
}
}

Export/Download presentations and SpreadSheet impersonate other domain users with using administrative access

I need to export/download all files of the other domain users. I used the client login with administer account to see the all files of domain users. however,only document can be export/download,others are fail.
so what is the download url format of the others(For File,pdf,presentation and spreadsheet)??
my document download url is
https://docs.google.com/feeds/download/documents/Export?xoauth_requestor=admin#domain.com&docId=<id>&exportFormat=doc
my program is as following:
public class AuthExample {
private static DocsService docService = new DocsService("Auth Example");
public static void main(String[] args)
throws Exception
{
String adminUser = admin;
String adminPassword = adminpasswd;
String impersonatedUser = "user#domain.com";
docService.setUserCredentials(adminUser, adminPassword);
URL url = new URL( "https://docs.google.com/feeds/" + impersonatedUser + "/private/full");
DocumentListFeed feed = docService.getFeed(url, DocumentListFeed.class);
for (DocumentListEntry entry : feed.getEntries()) {
String title = entry.getTitle().getPlainText();
System.out.println( title );
String type = entry.getType();
if ( type.equals("document") )
{
String encodedAdminUser = URLEncoder.encode(adminUser);
String resourceId = entry.getResourceId();
String resourceIdNoPrefix = resourceId.substring( resourceId.indexOf(':')+1 );
String downloadUrl =
"https://docs.google.com/feeds/download/documents/Export" +
"?xoauth_requestor=" + encodedAdminUser +
"&docId=" + resourceIdNoPrefix +
"&exportFormat=doc";
downloadFile( downloadUrl, title + ".doc" );
}
}
}
// Method pasted directly from Google documentation
public static void downloadFile(String exportUrl, String filepath)
throws IOException, MalformedURLException, ServiceException
{
System.out.println("Exporting document from: " + exportUrl);
MediaContent mc = new MediaContent();
mc.setUri(exportUrl);
MediaSource ms = docService.getMedia(mc);
InputStream inStream = null;
FileOutputStream outStream = null;
try {
inStream = ms.getInputStream();
outStream = new FileOutputStream(filepath);
int c;
while ((c = inStream.read()) != -1) {
outStream.write(c);
}
} finally {
if (inStream != null) {
inStream.close();
}
if (outStream != null) {
outStream.flush();
outStream.close();
}
}
}
}
Don't build the download link manually, instead use the entry's content link as explained in the docs:
https://developers.google.com/google-apps/documents-list/#downloading_documents_and_files

Categories