我正在使用此代码(来自www.internetria.com)拍摄照片并上传到服务器:
的onCreate:
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
Uri output = Uri.fromFile(new File(foto));
intent.putExtra(MediaStore.EXTRA_OUTPUT, output);
startActivityForResult(intent, TAKE_PICTURE);
Run Code Online (Sandbox Code Playgroud)
onActivityResult:
ImageView iv = (ImageView) findViewById(R.id.imageView1);
iv.setImageBitmap(BitmapFactory.decodeFile(foto));
File file = new File(foto);
if (file.exists()) {
UploaderFoto nuevaTarea = new UploaderFoto();
nuevaTarea.execute(foto);
}
else
Toast.makeText(getApplicationContext(), "No se ha realizado la foto", Toast.LENGTH_SHORT).show();
Run Code Online (Sandbox Code Playgroud)
UploaderFoto:
ProgressDialog pDialog;
String miFoto = "";
@Override
protected Void doInBackground(String... params) {
miFoto = params[0];
try {
HttpClient httpclient = new DefaultHttpClient();
httpclient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
HttpPost httppost = new HttpPost("http://servidor.com/up.php");
File …Run Code Online (Sandbox Code Playgroud) 大多数网站都希望压缩其内容以节省带宽.但是,对于运行PHP的apache服务器,有两种方法可以实现 - 使用PHP或使用apache.那么哪一个在您的服务器上更快或更容易?
例如,在PHP中,我在页面的开头运行以下函数来启用它:
/**
* Gzip compress page output
* Original function came from wordpress.org
*/
function gzip_compression() {
//If no encoding was given - then it must not be able to accept gzip pages
if( empty($_SERVER['HTTP_ACCEPT_ENCODING']) ) { return false; }
//If zlib is not ALREADY compressing the page - and ob_gzhandler is set
if (( ini_get('zlib.output_compression') == 'On'
OR ini_get('zlib.output_compression_level') > 0 )
OR ini_get('output_handler') == 'ob_gzhandler' ) {
return false;
}
//Else if zlib is …Run Code Online (Sandbox Code Playgroud) 我有一个map-reduce java程序,我尝试只压缩mapper输出但不压缩reducer输出.我认为这可以通过在Configuration实例中设置以下属性来实现,如下所示.但是,当我运行我的作业时,reducer生成的输出仍然被压缩,因为生成的文件是:part-r-00000.gz.有没有人成功地压缩了映射器数据而不是缩减器?这甚至可能吗?
//压缩映射器输出
conf.setBoolean("mapred.output.compress", true);
conf.set("mapred.output.compression.type", CompressionType.BLOCK.toString());
conf.setClass("mapred.output.compression.codec", GzipCodec.class, CompressionCodec.class);
Run Code Online (Sandbox Code Playgroud) 压缩文件可以分为以下逻辑组
a.您正在处理的操作系统(*ix,Win)等
.不同类型的压缩算法(即.zip,.Z,.bz2,.rar,.gzip).至少来自大多数使用压缩文件的标准列表.
C.然后我们有tar球机制 - 我认为没有压缩.但它更像是连接.
现在,如果我们开始解决上面的压缩文件集,
a.选项(a)将由python处理,因为它是与平台无关的语言.
湾 选项(b)和(c)似乎有问题.
我需要什么
如何识别文件类型(压缩类型)然后对它们进行UN压缩?
喜欢:
fileType = getFileType(fileName)
switch(fileType):
case .rar: unrar....
case .zip: unzip....
etc
Run Code Online (Sandbox Code Playgroud)
所以基本问题是我们如何根据文件识别压缩算法(假设没有提供扩展或不正确)?在python中有没有特定的方法呢?
在阅读了gzip压缩如何工作后,它让我思考.如果Origin和Proxy服务器(CDN)都支持gzip是否需要添加Vary: Accept-Encoding头?
我知道GZIP是LZ77和Huffman编码的组合,可以配置1-9之间的级别,其中1表示最快的压缩(压缩较少),9表示最慢的压缩方法(最佳压缩).
我的问题是,级别的选择是否只会影响压缩过程,还是因为压缩的级别而导致解压缩还会产生额外的成本?
我问,因为如果客户支持它,通常很多Web服务器会动态地进行GZIP响应,例如Accept-Encoding: gzip.我很欣赏在飞行时这样做6级的水平可能是普通情况的好选择,因为它在速度和压缩之间提供了良好的平衡.
但是,如果我有一堆静态资产,我可以提前GZIP一次 - 而且永远不需要再次这样做 - 使用最高但最慢的压缩级别会有任何不利之处吗?即,如果使用较低的压缩级别,则客户端现在会产生额外的开销.
有没有人知道纬度/经度坐标的最有效表示?消费者GPS设备的准确度应该足够了.
大多数实现似乎都double用于每个单元,但我怀疑一个float或定点格式应该足够了.我很想听到任何试图压缩或存储这些值的大数组的人.
编辑:
换句话说,对于消费级设备来说,表示纬度/经度所需的最低精度是多少?
我正在寻找一些关于在.NET中压缩数据的建议,除了使用GZipStream该类.
我正在寻找字节数组的快速和高压缩,以便能够通过TCP发送它们.
我有时需要将更大的JSON请求有效负载发布到我的ASP.Net核心控制器.有效载荷的大小保证(至少在我看来)压缩它.由于ASP.Net核心控制器似乎不支持开箱即用的压缩请求内容,因此我推出了自己的中间件.
实现这个是微不足道的,我不确定我是否在这里遗漏了一些东西.要么是因为有一种内置的方法来实现这一目标,要么是因为我从安全性或性能角度出现了一些重大错误?
public class GzipRequestContentEncodingMiddleware
{
public GzipRequestContentEncodingMiddleware(RequestDelegate next)
{
if (next == null)
throw new ArgumentNullException(nameof(next));
this.next = next;
}
private readonly RequestDelegate next;
private const string ContentEncodingHeader = "Content-Encoding";
private const string ContentEncodingGzip = "gzip";
private const string ContentEncodingDeflate = "deflate";
public async Task Invoke(HttpContext context)
{
if (context.Request.Headers.Keys.Contains(ContentEncodingHeader) &&
(context.Request.Headers[ContentEncodingHeader] == ContentEncodingGzip ||
context.Request.Headers[ContentEncodingHeader] == ContentEncodingDeflate))
{
var contentEncoding = context.Request.Headers[ContentEncodingHeader];
context.Request.Headers.Remove(ContentEncodingHeader);
var destination = new MemoryStream();
using (var decompressor = contentEncoding == ContentEncodingGzip
? (Stream) new …Run Code Online (Sandbox Code Playgroud)