I have a spring2.0 application and we are using uploadify jquery plugin 2.1 version to implement the image upload functionality.
Problem is: when I am trying to upload any image in java code it is saying it's resolution is 0dpi. But i checked i was 300dpi.
Why is it happening? My uploadify configuration is:
$('#imageFile1').uploadify({
'uploader' : '../uploadify/uploadify.swf',
'script' : 'images.htm',
'scriptData' : {'currentFormSpecId' : '${myCommand.formId}'},
'cancelImg' : 'cancel.png',
'auto' : false,
'multi' : true,
'wmode' : 'transparent',
'width' : 130,
'queueID' : 'fileQueue',
'queueSizeLimit' : 15,
'folder' : '../uploadify',
'fileDesc' : '*.jpg;*.jpeg;*.tif;*.tiff;*.eps',
'fileExt' : '*.jpg;*.jpeg;*.tif;*.tiff;*.eps',
'sizeLimit' : 102400000,
'onError': function(event, queueID, fileObj, errorObj) {
// Error display
},
'onComplete': function(event, queueID, fileObj, response, data) {
//success display
});
Java code
public ModelAndView uploadImagesToDisk (HttpServletRequest request,
HttpServletResponse response, Object command, BindException errors) throws Exception {
String currentFormId = request.getParameter("currentFormSpecId");
DefaultMultipartHttpServletRequest multipartHttpServletRequest =
(DefaultMultipartHttpServletRequest) request;
MultipartFile multipartFile = multipartHttpServletRequest.getFile("Filedata");
OutputStream outputStream = null;
try {
String imageFileName = multipartFile.getOriginalFilename();
String imageFileExtension = getFileExtension(multipartFile);
Image image = Image.getInstance(multipartFile.getBytes());
if ((image.getDpiX() < MINIMUM_DPI) || (image.getDpiY() < MINIMUM_DPI)) {
throw new Exception("ERROR: The image (" + multipartFile.getOriginalFilename()
+ ", " + image.getDpiX() + " dpi) " +
" your are attempting to upload does not meet the requirements " +
"for minimum resolution of 300 dpi. Please upload another image.");
}
}
in above code image.getDpiX() is always coming zero.
one more weird thing I noticed: When I checked the image resolution in my window7 machine it is saying it is 300dpi but when I am checking the same image in windows server machine(using citrix I am connecting and it has low screen resolution), it is showing 96dpi. Why is it happening?
Please let me know you want me to post anything else.
I was facing two problems here:
In java code, it was showing 0 DPI resolution for the image. So I
found two solutions for that. a) I found that few image
information is missing so, I opened that Image and saved it again
with different name, after that it was working fine.
b) I update
the iText.jar in my project then also it worked fine without doing
anything with image.
As #chrylis said above in comments, it was showing default DPI for that image as that information was missing.
Related
I'm working on a java application that interacts with Word through an OLE library (org.eclipse.swt.ole.win32) to merge documents (mail merge).
the java method which makes it possible to merge has been working for several years without any particular problem.
but recently the data source can no longer be associated with the merge document.
This problem is random (on some workstations it works and on others it doesn't, yet same system configuration)
I have no explicit error reported on the java side
Here is the method that communicates with Word:
public void mergeDocument(File model, File source) throws Exception {
OleAutomation autoMailMerge = null;
LOGGER.log(new Status(IStatus.INFO, pluginID, "Merge d un document"));
LOGGER.log(new Status(IStatus.INFO, pluginID, "fichier modele: " + model.getCanonicalPath()));
LOGGER.log(new Status(IStatus.INFO, pluginID, "fichier source: " + source.getPath()));
openDocumentReadOnly(model);
autoMailMerge = OLEHelper.getAutomationProperty(autoDocument, "MailMerge");
if ((source != null) && (source.exists()) && (!source.isDirectory())) {
OLEHelper.invoke(autoMailMerge, "OpenDataSource", source.getPath());
} else {
throw new MSWordOleInterfaceException(MSWordOleInterfaceCst.MSG_ERROR_EMPTY_SOURCE_PATH
+ ((source == null) ? "null" : source.getPath()));
}
OLEHelper.invoke(autoMailMerge, "Execute");
OleAutomation autoDocumentMerged = getActiveDocument();
closeDocument(autoDocument);
activateDocument(autoDocumentMerged);
autoDocument = autoDocumentMerged;
autoMailMerge.dispose();
}
Merging by hand from Word (associating the data source and merging) works on workstations where the java application does not work.
thanks to the OLE command I validated that it is the data source which is not passed (on a workstation which works I have a return with the name of the source, on one or it does not work the return is empty)
LOGGER.log(new Status(IStatus.INFO, pluginID, "data source name: "
+ OLEHelper.getVariantProperty(autoDataSource, "Name").getString()));
-a temporary solution has been found, by deleting the registry key related to office:
HKEY_CURRENT_USER\SOFTWARE\Microsoft\Office\16.0\Word\DocumentTemplateCache
but this is only a temporary solution, the problem comes back.
I`m programming a little file server which gets documents via HTTP-POST requests from another software.
The requests are always "multipart/form-data" types, so I`d like to split it via .getParts();
Unfortunately I always get a "java.io.IOException: Incomplete parts" or it does not find the part.
Is there something wrong with my code or is there a problem with the request?
I`m using a embedded Jetty server with Eclipse
public void create_document() {
String lv_path = gr_request.getParameter("contRep") + File.separator + gr_request.getParameter("docId");
Part lr_part = null;
try {
System.out.println(gr_request.getContentType());
//for testing
Part lr_test = gr_request.getPart("data");
System.out.println("1");
System.out.println(lr_test);
//the actual part
Collection<Part> lr_parts = gr_request.getParts();
for (Iterator<Part> i = lr_parts.iterator(); i.hasNext();) {
lr_part = ((Iterator<Part>) lr_parts).next();
//again for testing
System.out.println("content Type" + lr_part.getContentType());
System.out.println("name" + lr_part.getName());
System.out.println("content Type" + lr_part.getContentType());
String test = lv_path + ".jpg";
lr_part.write(test);
the log is
2017-11-28 11:07:47.941:INFO:oejs.Server:main: jetty-9.0.4.v20130625
2017-11-28 11:07:48.222:INFO:oejs.ServerConnector:main: StartedServerConnector#7165cbeb{HTTP/1.1}{0.0.0.0:1090}
Erkannte Aktion: CREATE_DOCUMENT
2017-11-2811:07:54.469:WARN:oejs.Request:qtp424058530-15:java.io.IOException:Incomplete parts
multipart/form-data; boundary=KoZIhvcNAQcB
1
null
The MultiPartConfig was done by
MultipartConfigElement multipartConfigElement = newMultipartConfigElement((String)null);
ir_request.setAttribute(Request.__MULTIPART_CONFIG_ELEMENT, multipartConfigElement);
Beginning of the body of a transmitted PDF file:
--KoZIhvcNAQcB
Content-Disposition: form-data; filename="data"
X-compId: data
Content-Type: application/pdf
Content-Length: 182370
%PDF-1.7
%µµµµ
1 0 obj
...and so on...
182188
%%EOF
--KoZIhvcNAQcB--
It seems that there is a problem with the request.
I changed the "filename" tag to "name" while receiving the request.
Now it's running
I wanted to loop through a folder containig .mp3 files and changing their album names (if they don't have one) to their title (e.g. Remix.mp3 with Title "Remix" gets the Album "Remix") using mp3agic.
This is my code so far:
if (mp3file.hasId3v1Tag()) {
ID3v1 id3v1Tag = mp3file.getId3v1Tag();
try {
if (id3v1Tag.getAlbum().equals("")) {
id3v1Tag.setAlbum(id3v1Tag.getTitle());
mp3file.save(SAVE_DIR + "\\" + child.getName());
System.out.println(SAVE_DIR + "/" + child.getName());
} else {
mp3file.save(SAVE_DIR + "/" + child.getName());
}
} catch (Exception e) {
mp3file.save(SAVE_DIR + "/" + child.getName());
}
}
I get the following error:
Exception in thread "main" com.mpatric.mp3agic.NotSupportedException: Packing Obselete frames is not supported
at com.mpatric.mp3agic.ID3v2ObseleteFrame.packFrame(ID3v2ObseleteFrame.java:32)
at com.mpatric.mp3agic.ID3v2Frame.toBytes(ID3v2Frame.java:83)
at com.mpatric.mp3agic.AbstractID3v2Tag.packSpecifiedFrames(AbstractID3v2Tag.java:275)
at com.mpatric.mp3agic.AbstractID3v2Tag.packFrames(AbstractID3v2Tag.java:261)
at com.mpatric.mp3agic.AbstractID3v2Tag.packTag(AbstractID3v2Tag.java:227)
at com.mpatric.mp3agic.AbstractID3v2Tag.toBytes(AbstractID3v2Tag.java:218)
at com.mpatric.mp3agic.Mp3File.save(Mp3File.java:450)
at de.thejetstream.main.Iterator.(Iterator.java:57)
at de.thejetstream.main.Main.main(Main.java:12)
at this file:
name: Feel Good in Black and Yellow.mp3
title: Feel Good in Black and Yellow (feat. Gorillaz & De La Soul)
album: Black and Yellow - Single
It crashes at line 57, which equals to the last save (in the catch).
What is the problem with this code? Is it just because the file uses an old kind of codec or something like this?
I found the solution:
The problem was that these files used ip3v2 tags instead of ip3v1. Simply checking which on it is and adjusting the code accordingly solved everything.
Like most of the people has asked the similar question. But so far, I didn't found a solution yet.
var img = [
C:/a/b/1.png,
C:/a/b/2.png
];
$j.each(img, function(){
$j('#imagesList').append('<li><img src=file:///"' + this + '" /></li>');
});
first make array like this
var img = [
"C:/a/b/1.png",
"C:/a/b/2.png"
];
then
$j.each(img, function(i, val){
$j('#imagesList').append('<li><img src=file:///"' + val + '" /></li>');
});
Your browser security prevents loading images from local hard disks.
A long time ago this was allowed, you could even load an image from something like D:/ and ope n the CD drive.
Here is my code on gist
This camera app is follow Android Official Guide
My device is Nexus 5 with kikat 4.4.2
#Override
public void onFaceDetection(Camera.Face[] faces, Camera camera) {
if (faces.length > 0){
Camera.Face f = faces[0];
Log.v(TAG, ("Detected" + faces.length + "faces,the ID of first face is:" + f.id ));
Log.v(TAG, "leftEye : " + f.leftEye);
Log.v(TAG, "mouth : " + f.mouth);
Log.v(TAG, "rect : " + f.rect);
Log.v(TAG, "rightEye: " + f.rightEye);
mCamera.stopFaceDetection();
}
}
The output above code when detect a human face is:
Detected 1 faces,the ID of first face is:-1
FaceActivity﹕ leftEye : null
FaceActivity﹕ mouth : null
FaceActivity﹕ rect : Rect(-393, 356 - -213, 676)
FaceActivity﹕ rightEye: null
So, I want to know whether my Nexus 5 support FaceDetect?If not, how could it implement Screen Lock with Face Unlock?
I found out the reason for this problem. It's all about RGB_564. Android has an API to recognize the human face, but only RGB_564 bitmaps are supported. Face detection is a very cost intensive action. So by default, the camera's FaceDetect feature only recognizes basic face information, and that was the reason why face.leftEye is null.