Last active
December 11, 2015 13:08
-
-
Save DJCordhose/4604886 to your computer and use it in GitHub Desktop.
Ultradox simple file download
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import static com.google.appengine.api.urlfetch.FetchOptions.Builder.withDefaults; | |
import java.io.IOException; | |
import java.net.URL; | |
import javax.servlet.http.HttpServlet; | |
import javax.servlet.http.HttpServletRequest; | |
import javax.servlet.http.HttpServletResponse; | |
import com.google.appengine.api.urlfetch.HTTPMethod; | |
import com.google.appengine.api.urlfetch.HTTPRequest; | |
import com.google.appengine.api.urlfetch.HTTPResponse; | |
import com.google.appengine.api.urlfetch.URLFetchService; | |
import com.google.appengine.api.urlfetch.URLFetchServiceFactory; | |
@SuppressWarnings("serial") | |
public class App_Engine_SandboxServlet extends HttpServlet { | |
public void doGet(HttpServletRequest req, HttpServletResponse resp) | |
throws IOException { | |
URLFetchService urlFetchService = URLFetchServiceFactory.getURLFetchService(); | |
URL url = new URL( | |
"http://www.ultradox.com/ultradoc/execute?id=57qNs8JVJFf6WcPRqsCuI7wBlIPT5M&action=DOWNLOAD"); | |
HTTPRequest request = new HTTPRequest(url, HTTPMethod.GET, withDefaults().setDeadline(30.0)); | |
HTTPResponse response = urlFetchService.fetch(request); | |
resp.setContentType("application/pdf"); | |
resp.getOutputStream().write(response.getContent()); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function download() { | |
var response = UrlFetchApp.fetch('http://www.ultradox.com/ultradoc/execute?id=57qNs8JVJFf6WcPRqsCuI7wBlIPT5M&action=DOWNLOAD'); | |
var blob = response.getBlob(); | |
Logger.log(blob.getName()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.File; | |
import java.io.FileOutputStream; | |
import java.io.IOException; | |
import java.io.InputStream; | |
import java.io.OutputStream; | |
import java.net.URL; | |
public class Main { | |
public static void main(String[] args) throws Exception { | |
URL url = new URL( | |
"http://www.ultradox.com/ultradoc/execute?id=57qNs8JVJFf6WcPRqsCuI7wBlIPT5M&action=DOWNLOAD"); | |
InputStream inputStream = url.openStream(); | |
FileOutputStream outputStream = new FileOutputStream(new File( | |
"processed.pdf")); | |
transfer(inputStream, outputStream); | |
} | |
private static void transfer(InputStream inputStream, | |
OutputStream outputStream) throws IOException { | |
byte[] buffer = new byte[1024]; | |
int len; | |
while ((len = inputStream.read(buffer)) != -1) { | |
outputStream.write(buffer, 0, len); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment