使用HTML5分块,我可以用较小的片段进行文件上传.但问题开始时,它开始使用多个http POST请求,这将导致计算机减速,或可能崩溃.反正有没有在一个http请求下分割文件..所以,如果我有5个文件,它将只有5个http请求,尽管我使用html5拆分块
例如:如果我上传5个文件,每个文件将被拆分为1mb块,所以如果第一个文件是10mb,那么它将变成10个1mb块.问题是,每个块将在1个http请求下,所以只有第一个文件它将是10个HTTP请求.想象一下,如果我有1GB文件,它将成为1000 HTTP请求并减慢计算机速度.
这是示例代码:
//Prepare element progress after the page load completely
var uploaders = [];
var totalChunks = 0;
var progress;
var bars;
$(document).ready(function() {
//progress = document.querySelector('progress');
//bars = document.querySelector('#bars');
});
//function for after the button is clicked, slice the file
//and call upload function
function sendRequest() {
//clean the screen
//bars.innerHTML = '';
var file = document.getElementById('fileToUpload');
for(var i = 0; i < file.files.length; i++) {
var blob = file.files[i];
var originalFileName = blob.name;
var filePart …Run Code Online (Sandbox Code Playgroud) 为什么这段代码不起作用?我怎么能在formdata中附加额外的数据?
fd = new FormData();
fd.append("file_for_upload", file_blob_chunk);
fd.append("test", "testing");
fd.append("test2", original_file_name);
xhr = new XMLHttpRequest();
xhr.open("POST", "files/index/" + file_name + '/' + file_part, true);
xhr.send(fd);
Run Code Online (Sandbox Code Playgroud)
当我调试它时,我可以看到'file_for_upload'的数组,但不是'test'或'test2'.
基本上通常你会使用$ _FILES然后它应该显示file_for_upload数组.它的工作方式.但现在我需要添加另一个,例如original_file_name.但它没有显示其他数组.
是否有可能因为我在html页面中只有一个用于文件上传的表单,而没有另外两个文本框表单?
因此,我创建了一个用于合并文件的c ++可执行文件.我有43个文件,每个文件大小为100MB.所以一共约4.3GB.
两种情况:
一:如果文件名是1,2,3,4,5,6,...,43则需要大约2分钟才能完成合并.
二:如果文件名是This File.ova0,这个File.ova1,...,这个File.ova42它将需要大约7分钟才能完成合并.
这是完全相同的文件,我只是重命名该文件.知道什么是错的吗?
这是c ++代码
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include "boost/filesystem.hpp"
namespace bfs = boost::filesystem;
#pragma warning(disable : 4244)
typedef std::vector<std::string> FileVector;
int main(int argc, char **argv)
{
int bucketSize = 3024 * 3024;
FileVector Files;
//Check all command-line params to see if they exist..
for(int i = 1; i < argc; i++)
{
if(!bfs::exists(argv[i]))
{
std::cerr << "Failed to locate required part file: " << argv[i] << std::endl;
return 1;
} …Run Code Online (Sandbox Code Playgroud) 我有一个文件上传功能,并使用html5中的slice api,我将每个文件切成1MB块,但最终结果导致文件被破坏.有时,最终结果比原始文件小,有时即使它是正确的大小,我仍然无法打开它.有谁有任何想法?或解决方案?这是切片的一部分
var uploaders = [];
var i = 0;
$(document).ready(function() {
var progress = document.querySelector('progress');
var bars = document.querySelector('#bars');
});
//function for after the button is clicked, slice the file
//and call upload function
function sendRequest() {
//clean the screen
bars.innerHTML = '';
var blob = document.getElementById('fileToUpload').files[0];
var originalFileName = blob.name;
const BYTES_PER_CHUNK = 1 * 1024 * 1024; // 10MB chunk sizes.
const SIZE = blob.size;
var start = 0;
var end = BYTES_PER_CHUNK;
while( start < SIZE …Run Code Online (Sandbox Code Playgroud) 有人知道为什么upload.onprogress如果在单独的函数上不能正常工作?
代码正常工作(进度条缓慢移动):
xhr.upload.onprogress = function(e) {
if (e.lengthComputable) {
progress.value = (e.loaded / e.total) * 100;
}
};
Run Code Online (Sandbox Code Playgroud)
但如果我把它投入使用,它就不再起作用了:
xhr.upload.onprogress = uploadProgress(event);
function uploadProgress(e) {
if (e.lengthComputable) {
progress.value = (e.loaded / e.total) * 100;
}
}
Run Code Online (Sandbox Code Playgroud)
在第二个代码上,进度条在文件完成上传后直接跳转到100%而不是,在上传期间很好地移动到100%
所以,我已经尝试了所提供的解决方案,它实际上是有效的,如果我把功能放在里面.有没有办法把它放在功能之外?
function uploadFile(blobFile, fileName) {
...
...
// Listen to the upload progress for each upload.
xhr.upload.onprogress = uploadProgress;
// Progress Bar Calculation why it has to be in uploadFile function..
function uploadProgress(e) {
if (e.lengthComputable) {
progress.value = (e.loaded / e.total) …Run Code Online (Sandbox Code Playgroud) 我编写了一个 cakeshell 脚本,我计划使用 cronjob 来使用它。在手动运行它(在测试期间)时,有时我的网站会抛出 SplFileInfo 警告,例如:
Warning: SplFileInfo::openFile(/var/www/flat/app/tmp/cache/persistent/myapp_cake_core_file_map):
failed to open stream: Permission denied in /var/www/flat/lib/Cake/Cache/Engine/FileEngine.php on line 313
Warning (512): SplFileInfo::openFile(/var/www/flat/app/tmp/cache/models/myapp_cake_model_default_flat_list):
failed to open stream: Permission denied [CORE/Cake/Cache/Engine/FileEngine.php, line 313]
Warning (512): SplFileInfo::openFile(/var/www/flat/app/tmp/cache/models/myapp_cake_model_default_flat_list) [http://php.net/splfileinfo.openfile]:
failed to open stream: Permission denied [CORE/Cake/Cache/Engine/FileEngine.php, line 313]
Warning (512): _cake_model_ cache was unable to write 'default_flat_list' to File cache [CORE/Cake/Cache/Cache.php, line 309]
Warning (512): SplFileInfo::openFile(/var/www/flat/app/tmp/cache/persistent/myapp_cake_core_method_cache) [http://php.net/splfileinfo.openfile]:
failed to open stream: Permission denied [CORE/Cake/Cache/Engine/FileEngine.php, line 313]
Warning (512): SplFileInfo::openFile(/var/www/flat/app/tmp/cache/persistent/myapp_cake_core_method_cache) [http://php.net/splfileinfo.openfile]:
failed to open …Run Code Online (Sandbox Code Playgroud) 我有一个来自端点的数据并将其放入 MatTableDataSource。我能够让它为 MatSort 和 MatPaginator 工作,但需要使用 setTimeOut,这似乎不是执行此操作的正确方法。如果我删除它,它会抱怨“无法读取未定义类型的属性”,我认为这是因为它尚未初始化。
我也试过:
这是我当前的代码(正在运行,但使用 settimeout)
<div *ngIf="!isLoading">
<div *ngFor="let record of renderedData | async" matSort>
// ... some html to show the 'record'
<mat-paginator #paginator
[pageSizeOptions]="[5, 10, 20]">
</mat-paginator>
</div>
Run Code Online (Sandbox Code Playgroud)
组件
export class ResultsComponent implements OnInit, OnDestroy, AfterViewInit {
dataSource: MatTableDataSource<any> = new MatTableDataSource();
renderedData: Observable<any>;
@ViewChild(MatPaginator) paginator: MatPaginator;
@ViewChild(MatSort) sort: MatSort;
constructor(some service) {}
ngOnInit() {
const accountId = someOtherService.getAccountId();
this.someService.getData(accountId)
.subscribe((myData) => {
this.dataSource …Run Code Online (Sandbox Code Playgroud) 我有
Contact Table : id, first_name, last_name, company_id
Company Table : id, name
Run Code Online (Sandbox Code Playgroud)
我想在Contact Table中创建虚拟字段,因此它将显示为"contactInCompany"
"first_name last_name - Company.name" e.g: Andre Robin - Google
Run Code Online (Sandbox Code Playgroud)
我怎么能实现这一点,我尝试这种方式,但它不起作用,它不接受另一个虚拟字段作为输入
public $virtualFields = array(
'companyName' => 'SELECT name FROM companies where id = Contact.company_id',
'customerWithCompany' => "CONCAT(Contact.first_name, ' ',
Contact.last_name, ' ', Contact.companyName, '')"
);
Run Code Online (Sandbox Code Playgroud)
我也用这种方式尝试过它并不起作用
'customerWithCompany' => "CONCAT(Contact.first_name, ' ', Contact.last_name, '-',
SELECT name FROM companies where id = Contact.company_id)"
Run Code Online (Sandbox Code Playgroud)
我经常需要这个,我会使用它来放入下拉选择框以选择联系人,所以我希望将联系人名称与公司一起显示
所以,在最新的更新之前,我使用onListItemClick监听器,它工作正常,但现在我尝试使用RecyclerView,我不知道如何为每个项目实现onClick,这将打开一个新的活动..
这就是我以前的样子
public class SermonsFragment extends Fragment {
@Override
public void onListItemClick(ListView list, View v, int position, long id) {
Intent mediaStreamIntent = new Intent(getActivity(), MediaStreamPlayer.class);
mediaStreamIntent.putExtra("sermon_details", (android.os.Parcelable) list.getItemAtPosition(position));
startActivity(mediaStreamIntent);
}
}
Run Code Online (Sandbox Code Playgroud)
但现在,我没有使用listview而是创建了一个布道适配器,它看起来像这样
public class SermonListAdapter extends RecyclerView.Adapter<SermonListAdapter.ViewHolder>{
private ArrayList<Sermon> mDataset;
// Provide a reference to the views for each data item
// Complex data items may need more than one view per item, and
// you provide access to all the views for a data item in a view …Run Code Online (Sandbox Code Playgroud) android android-intent android-cardview recycler-adapter android-recyclerview
如果我有一个目录,其中的文件列表如下所示:
Something_2015020820.txt
something_5294032944.txt.a
something_2015324234.txt
Something_2014435353.txt.a
Run Code Online (Sandbox Code Playgroud)
并且我想按最旧的日期(而不是文件名)获取文件排序列表,结果应该采用与 something_xxxxxxx.txt 匹配的任何内容。因此,不包括以“.a”结尾的任何内容。在这种情况下它应该返回
Something_2015020820.txt
something_2015324234.txt
Run Code Online (Sandbox Code Playgroud)
我做了一些谷歌搜索,似乎我可以使用 glob
$listOfFiles = glob($this->directory . DIRECTORY_SEPARATOR . $this->pattern . "*");
Run Code Online (Sandbox Code Playgroud)
但我不确定模式。
如果您可以同时提供区分大小写和不区分大小写的模式,那就太棒了。匹配模式必须是 something_number.txt
php ×7
file-upload ×3
html5 ×3
javascript ×3
ajax ×2
cakephp ×2
file ×2
android ×1
angular ×1
c++ ×1
cakephp-2.0 ×1
database ×1
directory ×1
form-data ×1
glob ×1
merge ×1
mysql ×1
pagination ×1
regex ×1
shell ×1
sorting ×1
sql ×1
visual-c++ ×1