如何在服务器上部署pdf文件路径,如何在本地服务器上添加pdf文件或文本文件?...

我用了我的回答我的问题我自己:-D所以这里是谁了同样的问题解决....首先,我才知道,在服务器端插座URI不工作“的文件这个文件路径:/ //mnt/sdcard/APK/Video.apk“或其他类型的文件uri。只有“/mnt/sdcard/APK/Video.apk”在socket上工作。因此,从文件URI字符串其中有来自内容提供商得到的,我创造了我的服务器套接字文件。然后创建一个文件之后...我已经得到了我也文件大小....

private void addSDFileEntity(final Uri uri, HttpResponse response)

throws IOException {

if (mTransferStartedListener != null) {

mTransferStartedListener.started(uri);

}

Cursor c = mContext.getContentResolver().query(uri, null, null, null,

null);

c.moveToFirst();

int nameIndex = c.getColumnIndexOrThrow(NewSDCardContentProvider.SDFiles.Columns.DISPLAY_NAME);

String name = c.getString(nameIndex);

int dataIndex = c.getColumnIndexOrThrow(NewSDCardContentProvider.SDFiles.Columns._DATA);

String dataname = c.getString(dataIndex);

Uri data = Uri.parse(dataname);

if (name.endsWith(".pdf")) {

String contentTypepdf = "application/pdf";

File myFile = new File(dataname);

int reqLen = (int) myFile.length();

Log.d("apk len===>", "" + reqLen);

InputStream fis = new FileInputStream(myFile);

response.addHeader("Content-Type", contentTypepdf);

response.addHeader("Content-Length", "" + reqLen);

response.setEntity(new InputStreamEntity(fis, reqLen));

if (socket == null) {

socket.close();

}

}

if (name.endsWith(".apk")) {

String contentTypeapk = "application/vnd.android.package-archive";

File myFile = new File(dataname);

int reqLen = (int) myFile.length();

Log.d("apk len===>", "" + reqLen);

InputStream fis = new FileInputStream(myFile);

response.addHeader("Content-Type", contentTypeapk);

response.addHeader("Content-Length", "" + reqLen);

response.setEntity(new InputStreamEntity(fis, reqLen));

}

现在我在服务器套接字发送我的文件内容....

private void sendSDFileContent(

DefaultHttpServerConnection serverConnection,

RequestLine requestLine) throws IOException, HttpException {

HttpResponse response = new BasicHttpResponse(new HttpVersion(1, 1),

200, "OK");

String SDfileId = getSDFileId(requestLine.getUri());

Log.d("selected URI from server", SDfileId);

addSDFileEntity(Uri.withAppendedPath(

NewSDCardContentProvider.SDFiles.CONTENT_URI, SDfileId),

response);

serverConnection.sendResponseHeader(response);

serverConnection.sendResponseEntity(response);

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值