我的功能
public static String postFile(String url,String fileName, String userName) throws Exception {
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost(url);
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
final File file = new File(fileName);
ContentBody cfile=new FileBody(file);
builder.addPart("file",cfile);
builder.addTextBody("userName", userName);
final HttpEntity yourEntity = builder.build();
class ProgressiveEntity implements HttpEntity {
@Override
public void consumeContent() throws IOException {
yourEntity.consumeContent();
}
@Override
public InputStream getContent() throws IOException,
IllegalStateException {
return yourEntity.getContent();
}
@Override
public Header getContentEncoding() {
return yourEntity.getContentEncoding();
}
@Override
public long getContentLength() {
return yourEntity.getContentLength();
}
@Override
public Header getContentType() {
return yourEntity.getContentType();
}
@Override
public boolean isChunked() {
return yourEntity.isChunked();
}
@Override
public boolean isRepeatable() {
return yourEntity.isRepeatable();
}
@Override
public boolean isStreaming() {
return yourEntity.isStreaming();
} // CONSIDER put a _real_ delegator into here!
@Override
public void writeTo(OutputStream outstream) throws IOException {
class ProxyOutputStream extends FilterOutputStream {
/**
* @author Stephen Colebourne
*/
public ProxyOutputStream(OutputStream proxy) {
super(proxy);
}
public void write(int idx) throws IOException {
out.write(idx);
}
public void write(byte[] bts) throws IOException {
out.write(bts);
}
public void write(byte[] bts, int st, int end) throws IOException {
out.write(bts, st, end);
}
public void flush() throws IOException {
out.flush();
}
public void close() throws IOException {
out.close();
}
} // CONSIDER import this class (and risk more Jar File Hell)
class ProgressiveOutputStream extends ProxyOutputStream {
public ProgressiveOutputStream(OutputStream proxy) {
super(proxy);
}
public void write(byte[] bts, int st, int end) throws IOException {
// FIXME Put your progress bar stuff here!
out.write(bts, st, end);
}
}
yourEntity.writeTo(new ProgressiveOutputStream(outstream));
}
};
ProgressiveEntity myEntity = new ProgressiveEntity();
post.setEntity(myEntity);
HttpResponse response = client.execute(post);
return getContent(response);
}
public static String getContent(HttpResponse response) throws IOException {
BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
String body = "";
String content = "";
while ((body = rd.readLine()) != null)
{
content += body + "\n";
}
return content.trim();
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
compile "org.apache.httpcomponents:httpmime:4.3.6"
compile "org.apache.httpcomponents:httpclient:4.3.6"
compile "org.apache.httpcomponents:httpcore:4.2.4"
Error:Execution failed for task ':app:packageDebug'.
Error:Execution failed for task ':app:packageDebug'.
对于复制的文件错误,请使用:
packagingOptions {
exclude 'META-INF/DEPENDENCIES.txt'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/notice.txt'
exclude 'META-INF/license.txt'
exclude 'META-INF/dependencies.txt'
}
它不仅可以用Apache的libs解决许多“重复文件”,而且可以忽略依赖项错误。
每当我尝试运行“react-native run-android” 我失败了: 任务“:app:PackageDebug”执行失败 我试着结账给previus提交。我尝试删除android/app/build和re-build,我尝试删除debug.keystore并再次启动它。 他们都没有解决这个问题。 我之前在android虚拟设备中成功运行了我的应用程序,并且我已经把我的应用程序上传到了go
错误:任务': app: process DebugGoogleServices'执行失败。请通过更新google-services插件的版本(有关最新版本的信息可在https://bintray.com/android/android-tools/com.google.gms.google-services/获得)或更新com.google.android.gms的版本来解决版本冲突。 这是我得
null 如果从其中删除,似乎可以使我的发布版本运行。为什么会这样,有没有别的办法解决呢
在代码没有任何更改的情况下,当我尝试运行应用程序时,突然出现了这个错误: 错误:任务“:app:PackageDebug”执行失败。com.android.builder.packaging.packagerException:java.io.ioException:无法读取zip文件“C:\users\eliran\androidStudioProjects\forum\app\build\ou
我在android studio中的android项目中工作过,当我开始运行gradle构建时,显示了以下错误。有人帮我吗?有什么问题吗 错误:任务': app: transformClassesSusDexForDebug'执行失败。com.android.build.api.transform.TransformException:com.android.ide.common.process.
错误:任务执行失败 ': app:使用合并Java Res For Debug转换资源'。 com.android.build.api.transform.TransformException:com.android.builder.packaging.DuplicateFileException: APK META-INF/LICENSE File1中复制的重复文件: C:\用户Jithin-P