Getting Internal server error in file uploading? - linux

I am new to linux environment.I have a web application which is running fine in windows environment and it is developed using play framework.Now we want to move our application from windows to linux. Here issue is,while uploading files i'm getting internal server error.I have given permissions as 777 for folder.Even the controller doesn't invoke the method,how to solve it?I am unable to find where the error goes,For all help thanks in advance.
Error is :
Controller action :
#helper.form(action =routes.HoForms.uploadHoFormsByHeadOffice(),'enctype -> "multipart/form-data" ,'id -> "shiftSummaryForm")
{
}
In routes file :
POST /HeadOfficeForms/upload controllers.HoForms.uploadHoFormsByHeadOffice()
Controller method :
public static Result uploadHoFormsByHeadOffice() throws Exception {
Logger.info("#C HoForms -->> uploadHoFormsByHeadOffice() -->> ");
}
Upload method() :
public static Result uploadHoFormsByHeadOffice() throws Exception {
final String basePath = "/var/www/html/pdfs/";
Date date = new Date();
DateFormat format = new SimpleDateFormat("dd-MM-yyyy");
String startDate = format.format(date);
date = format.parse(startDate);
play.mvc.Http.MultipartFormData body = request().body()
.asMultipartFormData();
String formType = body.asFormUrlEncoded().get("formType")[0];
FilePart upFile = body.getFile("hoFormFiles");
String fileName = upFile.getFilename();
try {
File ftemp = new File(basePath + "HeadOfficeForms/" + formType
+ "");
ftemp.mkdirs();
String filePathString = "HeadOfficeForms/" + formType + "/"
+ fileName;
File f1 = new File(ftemp.getAbsolutePath() + "/" + fileName);
File file = upFile.getFile();
file.setWritable(true);
file.setReadable(true);
f1.setWritable(true);
f1.setReadable(true);
Files.copy(file.toPath(), f1.toPath(), REPLACE_EXISTING);
HoForm.create(fileName, date, formType, filePathString);
flash("success", fileName + " Has been Successfully Uploaded");
} catch (IOException e) {
e.printStackTrace();
}
return redirect(routes.HoForms.showHoFormUploadPage());
}

Related

Writing to a new file in Azure App Service?

I have a Spring Boot application running in an Azure App Service. The application uses FileUtils.writeStringToFile from org.apache.commons.io.FileUtils to write a string to a new file:
private String staticPath = "/static";
[...]
public void uploadFileContent(String content) throws Exception {
try {
File dir = new File(staticPath);
if (!dir.exists()) dir.mkdirs();
String relativePath = DateFormatUtils.format(new Date(), Constants.DateFormatTemp.YYYYMM_SPRIT);
String newFileName = String.valueOf(System.currentTimeMillis()) + UUID.randomUUID();
File fileDir = new File(dir, relativePath);
if (!fileDir.exists()) fileDir.mkdirs();
File newFile = new File(fileDir, newFileName + Constants.Split.SPOT + "csv");
FileUtils.writeStringToFile(newFile, content);
} catch (Exception e) {
throw e;
}
}
Locally it works, but if I run it in Azure then I get:
java.io.IOException: File 'example.csv' could not be created
The exception occurs at the last line of the try block, i.e. FileUtils.writeStringToFile(newFile, content);
Does writing to file system in Azure require certain special operations?

Input output stream not working in Web Forms function

Can someone tell me why I keep getting a read and write timeout on this function? I have this as a code behind function on click even from a button. Everything as far as the data looks good until I get to the stream section and it still steps through, but when I check the Stream object contents after stepping into that object it states Read Timeout/Write Timeout: System invalid Operation Exception.
protected void SubmitToDB_Click(object sender, EventArgs e)
{
if (FileUploader.HasFile)
{
try
{
if (SectionDropDownList.SelectedValue != null)
{
if (TemplateDropDownList.SelectedValue != null)
{
// This gets the full file path on the client's machine ie: c:\test\myfile.txt
string strFilePath = FileUploader.PostedFile.FileName;
//use the System.IO Path.GetFileName method to get specifics about the file without needing to parse the path as a string
string strFileName = Path.GetFileName(strFilePath);
Int32 intFileSize = FileUploader.PostedFile.ContentLength;
string strContentType = FileUploader.PostedFile.ContentType;
//Convert the uploaded file to a byte stream to save to your database. This could be a database table field of type Image in SQL Server
Stream strmStream = FileUploader.PostedFile.InputStream;
Int32 intFileLength = (Int32)strmStream.Length;
byte[] bytUpfile = new byte[intFileLength + 1];
strmStream.Read(bytUpfile, 0, intFileLength);
strmStream.Close();
saveFileToDb(strFileName, intFileSize, strContentType, bytUpfile); // or use FileUploader.SaveAs(Server.MapPath(".") + "filename") to save to the server's filesystem.
lblUploadResult.Text = "Upload Success. File was uploaded and saved to the database.";
}
}
}
catch (Exception err)
{
lblUploadResult.Text = "The file was not updloaded because the following error happened: " + err.ToString();
}
}
else
{
lblUploadResult.Text = "No File Uploaded because none was selected.";
}
}
Try something like this:
using (var fileStream = FileUploader.PostedFile.InputStream)
{
using (var reader = new BinaryReader(fileStream))
{
byte[] bytUpfile = reader.ReadBytes((Int32)fileStream.Length);
// SAVE TO DB...
}
}

missing resource bundle exception in java using weblogic

I have a requirement that I need to convert xsd file to POJO files. While using tomcat I didnot face any issue but when I am using weblogic I am getting error
Can't find resource for bundle java.util.PropertyResouceBundle,key JAXPSupportedProperty
File tmpDir = util.createTempPOJODirectory();
String xsdFilePath = convertToXSD(xmlResponse, tmpDir); // The xml response will be converted to XML file and then converted to XSD file
if (StringUtils.isNotBlank(xsdFilePath)) {
log("XSD location ::" + xsdFilePath + " and output location :: " + tmpDir);
// Setup schema compiler
SchemaCompiler sc = XJC.createSchemaCompiler();
sc.forcePackageName("");
// Setup SAX InputSource
File schemaFile = new File(xsdFilePath);
InputSource is = new InputSource(schemaFile.toURI().toString());
// is.setSystemId(schemaFile.getAbsolutePath());
// Parse & build
sc.parseSchema(is);
log("after parsing and building");
log("sc :: " + sc);
S2JJAXBModel model = null;
try {
model = sc.bind();
}
catch (Exception e1) {
log("Exception :: " + ExceptionUtils.getFullStackTrace(e1));
}
log("model :: " + model);
try {
JCodeModel jCodeModel = model.generateCode(null, null);
jCodeModel.build(tmpDir);
log("generation POJO's is success");
return "POJO are created under " + tmpDir + " successfully.";
}
catch (IOException e) {
log("unable to generate POJO's");
log("IOException occurs :: " + ExceptionUtils.getFullStackTrace(e));
}
catch (Exception e) {
log("Exception occurs :: " + ExceptionUtils.getFullStackTrace(e));
}`
For this I have used below jars :-
xsd-gen-0.2.1.jar
xom-1.2.5.jar
wiztools-commons-lib-0.4.1.jar
jaxb-xjc-2.2.11.jar
jaxb-core-2.2.11.jar
cli-7.jar
Thanks guys, I have resolved this issue by removing jaxb jars.

cannot access the file because it is using by another program Error

I have been fighting with this issue since last week.still not able to solve.
i am sending file to client machine once i get in server automatically.but so many time when i handle file it throw an error that Cannot access the file because it is using by another program.
below my code
private static string SaveFileStream(string filePath, Stream stream, string Filename1)
{
string localresponse;
try
{
//this.SaveFileStream(System.Configuration.ConfigurationSettings.AppSettings[fileToPush.FileType].ToString() + "\\" + fileToPush.FileName, new MemoryStream(fileToPush.Content));
if (File.Exists(filePath))
{
File.Delete(filePath);
}
using (var fileStream = new FileStream(filePath, FileMode.Create, FileAccess.Write))
{
stream.CopyTo(fileStream);
fileStream.Flush();
fileStream.Dispose();
}
FileInfo info = new FileInfo(filePath);
ExtractFile(info);
localresponse = "Successful";
}
catch (Exception ex)
{
localresponse = ex.Message;
}
return localresponse;
}

A generic error occurred in GDI+ selenium webdriver

I get generic error occurred in GDI+ for selenium webdriver.It was working fine still yesterday,But suddenly I get this error.
public string TakeScreenshot(IWebDriver driver, string SnapFolderPath, string TCID, string KeyFunction)
{
try
{
// driver.Manage().Window.Maximize();
ITakesScreenshot ssdriver = driver as ITakesScreenshot;
Screenshot screenshot = ssdriver.GetScreenshot();
string filePath = testReport + "\\" + TCID + "_" + KeyFunction + "_" + GetDateTimeforFilePath() + ".png";
screenshot.SaveAsFile(filePath, ImageFormat.Png);
return filePath;
}
catch (Exception ex)
{
return string.Empty;
}
}
Resolved this Issue .We need to give full access permission to the folder where we want to store the image.If we don't give full permission we get this error

Resources