Firstly, I Want to read excel file which user is uploading and saving data to DB.
I have tried load function using excel API.
Excel::load($file_name_real, function($input) {
$results = $input->all();
// $input->dump();
})->download('xls');
But its not happening So now I want to move File to server then will read file then will unlink. By following function
$input1->move('/laravel');
But its not moving file.
Related
I would like to get an image from REST API by using file_get_content() and store in Symfony2.
$image = file_get_contents('https://foobar, false, $context)
But I am stacked when I am trying to sage the file.
$image->move($app['config']['image_temp_realdir'], $filename);
This line cause "Error: Call to a member function move() on string".
I understand this file data is not a File entity, but how can I convert this into File Entity? Or any method I can use to get file instead of file_get_content()?
Thanks in advance to your help.
Sorry, the problem resolved.
Saved the file by file_put_contents() and created new File.
file_put_contents($app['config']['image_temp_realdir'].'/'.$filename, $image);
$file = new File($app['config']['image_temp_realdir'].'/'.$filename);
My project has this requirement where user uploads a CSV file which has to be pushed to sql server database.
I know we can use Spring batch to process large number of records. But I'm not able to find any tutorial/sample code for this requirement of mine.
All the tutorials which I came across just hardcoded the CSV file name and in-memory databases in it like below:
https://spring.io/guides/gs/batch-processing/
User Input file is available in shared drive location on schduled time with file name prefix as eg: stack_overlfow_dd-MM-yyyy HH:mm, on daily basis how can I poll the Network shared drive for every 5-10 minutes atleast for one hour daily if its matches with regex then upload to database.
How can I take the csv file first from shared location and store it in memory or somewhere and then configure spring batch to read that as input.
any help here would be appreciated. Thanks In advance
All the tutorials which I came across just hardcoded the CSV file name and in-memory databases
You can find samples in the official repo here. Here is an example where the input file name is not hardcoded but passed as a job parameter.
How can I take the csv file first from shared location and store it in memory or somewhere and then configure spring batch to read that as input.
You can proceed in two steps: download the file locally then read/process/write it to the database (See https://stackoverflow.com/a/52110781/5019386).
how can I poll the Network shared drive for every 5-10 minutes atleast for one hour daily if its matches with regex then upload to database.
Once you have defined your job, you can schedule it to run when you want using:
a scheduler like Quartz
or using Spring's task scheduling features.
or using a combination of Spring Integration and Spring Batch. Spring integration would poll the directory and then launches a Spring Batch job when appropriate. This approach is described here.
More details on job scheduling here.
You can make a service layer that can process excel file and read data from file and construct java object to save into DB. Here I have used apache POI to parse Excel data and read from excel sheet.
public class FileUploadService {
#Autowired
FileUploadDao fileUploadDao;
public String uploadFileData(String inputFilePath) {
Workbook workbook = null;
Sheet sheet = null;
try {
workbook = getWorkBook(new File(inputFilePath));
sheet = workbook.getSheetAt(0);
/*Build the header portion of the Output File*/
String headerDetails = "EmployeeId,EmployeeName,Address,Country";
String headerNames[] = headerDetails.split(",");
/*Read and process each Row*/
ArrayList < ExcelTemplateVO > employeeList = new ArrayList < > ();
Iterator < Row > rowIterator = sheet.iterator();
while (rowIterator.hasNext()) {
Row row = rowIterator.next();
//Read and process each column in row
ExcelTemplateVO excelTemplateVO = new ExcelTemplateVO();
int count = 0;
while (count < headerNames.length) {
String methodName = "set" + headerNames[count];
String inputCellValue = getCellValueBasedOnCellType(row, count++);
setValueIntoObject(excelTemplateVO, ExcelTemplateVO.class, methodName, "java.lang.String", inputCellValue);
}
employeeList.add(excelTemplateVO);
}
fileUploadDao.saveFileDataInDB(employeeList);
} catch (Exception ex) {
ex.printStackTrace();
}
return "Success";
}
I believe your question have already been answered here.
The author of the question has even uploaded a repository of his working result :
https://github.com/PriyankaBolisetty/SpringBatchUploadCSVFileToDatabase/tree/master/src/main/java/springbatch_example
You can retrieve and filter files' lists in a shared drive using JCIFS API method SmbFile.listFiles(String wildcard).
How do you append to the file instead of overwriting it?
The file-system module documentation explains how to write to a file:
The following example writes some text to a file. It will create a new
file or overwrite an existing file.
var documents = fs.knownFolders.documents();
var file = documents.getFile("Test_Write.txt");
// Writing text to the file.
file.writeText("Something")
.then(function () {
// Succeeded writing to the file.
}, function (error) {
// Failed to write to the file.
});
My end goal is to write log files to disk as the nativescript app runs. It'd be too inefficient to read the contents of the log file into memory, append the new log message, and then write it all back to the file.
UPDATE:
Ended up logging to an sqlite database. This has some benefits and drawbacks, but for other's trying to solve a similar issue it's another direction to try.
NativeScript currently doesn't provide a appendFile function for its file system module.
Reference: https://github.com/NativeScript/NativeScript/issues/4462
A sample implementation of appendFile (text only) can be found here: https://github.com/EddyVerbruggen/nativescript-node/blob/dc93ab48a84c410bc8d6f46527fb171799f8bfeb/fs.js#L233-L254
It is using the "read and then write" method as you said.
I want to actually transfer my dynamic value from the response data to Excel file in Jmeter... can anyone plz let me know the clear process for it ?
I used beanshell post processor but dint got the expected output...
Take a look at Apache POI - Java API To Access Microsoft Excel Format Files, this way you will be able to create, read and update Excel files from Beanshell code. The easiest way to add binary documents formats support to JMeter is using Apache Tika, given you have tika-app.jar in JMeter Classpath you will be able to view Excel files contents using View Results Tree listener and use Apache POI API to manipulate Excel files.
Minimal working code for creating an Excel file and adding to it JMeter variable value looks like:
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
Workbook wb = new XSSFWorkbook();
Sheet sheet = wb.createSheet("Sheet1");
Row row = sheet.createRow(0);
Cell cell = row.createCell(0);
cell.setCellValue(vars.get("your_variable"));
FileOutputStream fileOut = new FileOutputStream("FileCreatedByJMeter.xlsx");
wb.write(fileOut);
fileOut.close();
References:
Busy Developers' Guide to HSSF and XSSF Features
How to Extract Data From Files With JMeter
I am creating a web application using Laravel 5.
I want to use AngularJS.
I have created a file named all-products.php in views directory which contains data in JSON format.
When I gave path to this file in http.open() it gives an error as http://localhost/user/app/resources/views/all-products.php 404 (Not Found).
Here is my JS code:
var app = angular.module("products", []);
app.controller("productsController", function($scope, $http){
$http.get("http://localhost/user/app/resources/views/all-products.php").success(function(response) {
$scope.records = response.records;
});
});
Please tell me how I can solve this ?
Thanks in advance.
You need to put the file in your public directory e.g.
http.get("http://localhost/all-products.json")
Would be a file at path public\all-product.json (assuming your homepage is http://localhost).
Or, if the file is dynamically created, you need to create a route, and return the .json data from there using Response::json(['some data]);