how to update file name dynametically when upload in ionic 4 - ionic4

hi i am using Ionic 4 with angular 7 in my project.
Currently i am facing difficulties on upload image.
File Transfer works fine with a static name like:
let options: FileUploadOptions = {
fileKey: 'file',
fileName: 'name.jpg',
headers: {}
.....
}
it working fine. but i need dynamic name. so i updated accordingly
this.temp_image_name = new Date().getTime()+'.jpg';
let options: FileUploadOptions = {
fileKey: 'file',
fileName: this.temp_image_name,
headers: {}
.....
}
but it not working and file name return empty. have any idea on this issue.
Thanks

i solved the issue in server side, before save or upload i renamed the file.
$temp = explode(".", $_FILES["file"]["name"]);
$newfilename = time() . '.' . end($temp);
$target_path = $target_path . $newfilename;
and return the newfileName to use the name for next use.

I tested the snippet just to be sure that combining a number getTime() and a string was ok, but it didn't seem to have any issues:
You are using a class level variable which may be being affected by something.
Try:
let temp_image_name = new Date().getTime()+'.jpg';
let options: FileUploadOptions = {
fileKey: 'file',
fileName: temp_image_name,
headers: {}
.....
}
It seems like you should not be using this plugin at all anyway as it is deprecated.

Related

laravel 7 pdf-to-text | Could not read pdf file

I installed this laravel package to convert pdf file into text. https://github.com/spatie/pdf-to-text
I'm getting this error:
Could not read sample_1610656868.pdf
I tried passing the file statically by putting it in public folder and by giving path of uploaded file.
Here's my controller:
public function pdftotext(Request $request)
{
if($request->hasFile('file'))
{
// Get the file with extension
$filenameWithExt = $request->file('file')->getClientOriginalName();
//Get the file name
$filename = pathinfo($filenameWithExt, PATHINFO_FILENAME);
//Get the ext
$extension = $request->file('file')->getClientOriginalExtension();
//File name to store
$fileNameToStore = $filename.'_'.time().'.'.$extension;
//Upload File
$path = $request->file('file')->storeAS('public/ebutifier/pdf', $fileNameToStore);
}
// dd($path);
$location = public_path($path);
// $pdf = $request->input('file');
// dd($location);
// echo Pdf::getText($location, 'usr/bin/pdftotext');
$text = (new Pdf('public/ebutifier/pdf/'))
->setPdf($fileNameToStore)
->text();
return $text;
}
Not sure why it's not working any help would be appreciated.
You used spatie/pdf-to-text Package.
I also tried to use this package but it gave me this kind of error.
So, I used asika/pdf2text package and it worked properly
Asika/pdf2text pacakge
And this is my code
$path = public_path('/uploads/documents/'. $file_name);
$reader = new \Asika\Pdf2text;
$output = $reader->decode($path);
dd($output);
Hopefully, it will be helpful for you.

Trying to use angular-recorder: how to send result file to server?

I'm using this https://github.com/logbon72/angular-recorder and eventually i'll get mp3 file. How i can sent this file to server by POST request ?
Can i send the mp3 file to server or Blob only ?
i can not get result voice file.
logbon72/angular-recorder is a Fork of sathyapulse/angular-recorder. There, some people comment similar issues. Then copy the reply I sent to one of them:
Just search "control.save" in angular-audio-recorder.js file ( near line 377 ) and write this:
control.save = function (fileName) {
if (!service.isAvailable() || status.isRecording || !control.audioModel) {
return false;
}
var formData = new FormData();
var request = new XMLHttpRequest();
var content = control.audioModel;
var blob = new Blob([content], { type: "audio/mp3"});
formData.append("file", blob);
request.open("POST", "/app/api/upload/audioMessage.php", true);
request.send(formData);
};
Just in case, my uploader php file ( /app/api/upload/audioMessage.php ) is something like this:
<?php
$dest_dir = $_SERVER['DOCUMENT_ROOT'] . '/storage/audio_messages/';
if(!file_exists($dest_dir)) mkdir($dest_dir, 0777);
move_uploaded_file($_FILES['file']['tmp_name'], $dest_dir . uniqid() . ".mp3");
Pay atention to set the audioModel attribute in your audioRecorder directive.

Form serialize data:image/png;base64 data type json

Hello i have been developing cms but now got revision add one feature crop and resize images before upload in codeignter, here is simple demo
$('#btnsubmit').on("click", function(e) {
e.preventDefault();
$.ajax({
url: base_url + "welcome/add",
type: "POST",
data: $('#form').serialize(), //extract value in form
dataType: "JSON",
success: function(data) {
if (data.status) //if success close modal and reload ajax table
{
alert('success');
} else {
alert('failed');
}
$('#btnsubmit').text('save'); //change button text
$('#btnsubmit').attr('disabled', false); //set button enable
}
});
and this is my controller
$dataURL=$this->input->post('images_crop');
//$dataURL = $_POST["imageData"];
$dataURL = str_replace('data:image/png;base64,', '', $dataURL);
$dataURL = str_replace(' ', '+', $dataURL);
$image = base64_decode($dataURL);
$filename = date("d-m-Y-h-i-s") . '.' . 'png'; //renama file name based on time
$path = set_realpath('uploads/product/');
file_put_contents($path. $filename, $image);
$data = array (
'id_product_post'=>$this->input->post('id_product_post'),
'foto'=>$filename
);
$this->db->insert('li_product_foto',$data);
all i have got images success store in database and folder but the images is blank and 0kb, where do i wrong, thanks
/---------Solved by my self----------/
The reason why file is 0kb and blank cause i forget to remove old doc which came from Here Please see the code controller i make command, Hope some one in the future get help from this

How to pass param {overwrite: true} in Brocfile.js

info:
ember-cli: 0.2.5,
ember-cli-less: 1.3.3,
I have the next error:
Merge error: file assets/mobile.css.map exists in mobile/tmp/caching-writer-dest-dir_ZcaW3C.tmp and /mobile/tmp/caching-writer-dest-dir_E4iROO.tmp
Pass option { overwrite: true } to mergeTrees in order to have the latter file win.
I tried what say in this post and this other. But I still without results.
Thanks for your time
Since none of the methods mentioned in the previous links worked. I choose to modify the ember-cli-less package:
node_modules/ember-cli-less/node_modules/broccoli-merge-trees/index.js
I changed the line:
function TreeMerger (inputTrees, options) {
if (!(this instanceof TreeMerger)) return new TreeMerger(inputTrees, options)
if (!Array.isArray(inputTrees)) {
throw new Error('Expected array, got ' + inputTrees)
}
this.inputTrees = inputTrees
this.options = { overwrite: true } // <- This line
}
The mergeTrees module has an option for overwrite.
It's documented here: https://github.com/broccolijs/broccoli-merge-trees#options
Here's an example:
return new MergeTrees([app.toTree(), fonts], { overwrite: true });
If you are using mac, can you try find . -name '.DS_Store' -type f -delete?
I've a similar issue, and I was able to solve by deleting duplicate files.
Error message
Build failed.
Merge error: file .DS_Store exists in /Users/ember-proj/tmp/broccoli_merge_trees-input_base_path-qaWJUMIJ.tmp/0 and /Users/ember-proj/ai/tmp/broccoli_merge_trees-input_base_path-qaWJUMIJ.tmp/1
Pass option { overwrite: true } to mergeTrees in order to have the latter file win.
update ember-cli-less to latest version (now 1.5.3), then pass config like this.
'ember-cli-less': {
mergeTrees: {
overwrite: true
}
}
things would work

SharePoint 2010 Wiki Template Script Issue

I'm looking for a way to give my SharePoint users a way to create new wiki pages from an existing template. In the process of researching I found a great walkthrough that seems to fit the need (http://www.mssharepointtips.com/tip.asp?id=1072&page=2), but I'm having trouble getting it to work. The problem seems to lie in the assignment of a path to PATHTOWIKI-- if I use "/Weekly Update Wiki", the script returns an error of "There is no Web named '/Weekly Update Wiki'." If I use "Weekly Update Wiki" without the forward slash, I instead get an error of "There is no Web named '/sites/[parentSite]/[childSite]/Weekly Update Wiki/Weekly Update Wiki'."
Any ideas about what I'm not understanding here?
function myCreateProject() {
// Configure these for your environment
// include no slashes in paths
var PATHTOWIKI = "Weekly Update Wiki";
var PATHTOPAGES = "Pages";
// file name only for template page, no extension
var TEMPLATEFILENAME = "Template";
var myPathToWiki = encodeURIComponent(PATHTOWIKI);
var myPathToPages = PATHTOPAGES + "%2f";
var myTemplateFileName = encodeURIComponent(TEMPLATEFILENAME) + "%2easpx";
var EnteredProject = document.getElementById("NewProjName");
var myNewName = EnteredProject.value;
if(myNewName == "") {
alert('Please enter a name for the new project page');
} else {
myNewName = encodeURIComponent(myNewName) + "%2easpx"
$.ajax({
url: PATHTOWIKI + "/_vti_bin/_vti_aut/author.dll",
data: ( "method=move+document%3a14%2e0%2e0%2e4730&service%5fname="
+ myPathToWiki +
"&oldUrl=" + myPathToPages + myTemplateFileName +
"&newUrl=" + myPathToPages + myNewName +
"&url%5flist=%5b%5d&rename%5foption=nochangeall&put%5foption=edit&docopy=true"
),
success: function(data) {
var rpcmsg1 = getMessage(data, "message=", "<p>");
$("#myInfo").append("<br />" + rpcmsg1);
if(rpcmsg1.indexOf("successfully") < 0) {
// get error info
var rpcmsg2 = getMessage(data, "msg=", "<li>");
$("#myInfo").append("<br />" + rpcmsg2 + "<br />");
} else {
$("#myInfo").append("<br />Go to new page<br />");
}
},
type: "POST",
beforeSend: function(XMLHttpRequest) {
XMLHttpRequest.setRequestHeader("X-Vermeer-Content-Type",
"application/x-www-form-urlencoded");
}
});
}
}
Update: I figured out what needed to happen in my case. Since I couldn't get a grasp on the relative approach, I just went with the absolute path for PATHTOWIKI and slightly modified the append in the ajax call.
PATHTOWIKI:
var PATHTOWIKI = "https://[domain]/sites/[parentSite]/[childSite]";
append:
$("#myInfo").append("<br />Go to new page<br />");
The change in the latter line of code is subtle; since I used an absolute path in PATHTOWIKI, I just removed the leading forward slash in the anchor tag, so that <a href=\"/" became <a href=\"". This renders the script slightly less portable, but since it's a one-off effort I'll stick with this unless anything comes along to expand the scope.