我们正在尝试使用 Azure 中的 node.js 创建服务以进行下载。我们正在发送 writeStream 作为响应。
更新:
var option = new Object();
option.disableContentMD5Validation = true;
option.maximumExecutionTimeInMs = 20 * 60000;
fileService.getFileToStream(shareName, dirPath, fileName, response, option, function (error, result, response) {
if(!error) {
if(response.isSuccessful) {
console.log("Success!");
}
}
});
在下载小于 4MB 的文件时,它工作正常。但是当下载超过 4MB 时,它给出了错误。
java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(Unknown Source)
at java.net.SocketInputStream.read(Unknown Source)
at sun.security.ssl.InputRecord.readFully(Unknown Source)
at sun.security.ssl.InputRecord.read(Unknown Source)
at sun.security.ssl.SSLSocketImpl.readRecord(Unknown Source)
at sun.security.ssl.SSLSocketImpl.readDataRecord(Unknown Source)
at sun.security.ssl.AppInputStream.read(Unknown Source)
at java.io.BufferedInputStream.fill(Unknown Source)
at java.io.BufferedInputStream.read1(Unknown Source)
at java.io.BufferedInputStream.read(Unknown Source)
at sun.net.www.MeteredStream.read(Unknown Source)
at java.io.FilterInputStream.read(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection$HttpInputStream.read(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection$HttpInputStream.read(Unknown Source)
at FileserviceTest.sendGET(FileserviceTest.java:58)
at FileserviceTest.main(FileserviceTest.java:18)
下面是示例 java 客户端代码。
public static void sendGET() throws IOException {
FileOutputStream fos = null;
URL obj = new URL("https://crowdtest-fileservice.azure-mobile.net/api/files/");
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
con.setRequestMethod("GET");
con.setRequestProperty("sharename", "newamactashare");
con.setRequestProperty("directorypath", "MaheshApp/TestLibrary/");
con.setRequestProperty("filename", "Test.apk");
int responseCode = con.getResponseCode();
System.out.println("GET Response Code :: " + responseCode);
if (responseCode == HttpURLConnection.HTTP_OK) { // success
fos = new FileOutputStream("C:/Users/uma.maheshwaran/Desktop/Test.mt");
InputStream iin = con.getInputStream();
byte[] buffer = new byte[4096]; // declare 4KB buffer
int len;
// while we have availble data, continue downloading and storing to
// local file
while ((len = iin.read(buffer)) > 0) {
fos.write(buffer, 0, len);
}
iin.close();
fos.close();
// print result
System.out.println("Done");
} else {
BufferedReader br = new BufferedReader(new InputStreamReader(con.getErrorStream()));
String line = "";
while ((line = br.readLine()) != null) {
System.out.println(line);
}
System.out.println("GET request not worked");
}
}
我们可以将写入流转换为缓冲流吗?如果是这样,我们如何发送响应。或者有没有其他方法可以发送大量数据作为响应。请帮助我。我是 node.js 的新手。