File type check before uploading a file

Right now I have a processing page that uploads a file only of type zip. If you try submitting something other than a zip file, it throws an error. Is it possible to check the file type before uploading?
Something like this in pseudo code:
if (file type does not = zip ) {
     redirect to the homepage with cflocation
else {
     <cffile action="upload" ....  />

Not with ColdFusion, it does not run on the client and has no idea about the file until the client browser has sent it to the web server and the web server as put it into the server's temp directory.
Maybe with someting that runs on the client, like JavaScript.  But when dealing with files in the client browser you quickly run into security features that prevent you from doing much to prevent hackers from writing client code to farm unsupecting users systems for interesting files.

Similar Messages

  • How to delete one existing file before uploading a file with same name?

    Hello everybody.
    I am uploading a file to Tomcat server. But, the problem is:
    i want to delete an existing file in the server, if i upload a fresh file with same name. In other words, "First check for the file with the same name in the server. If it exists, then delete existing file in the server and upload fresh one". If such file doesnot exist, then upload the file to server.
    I have given deleteonExit()
    but, for the first time when user is uploading, i want to check for the file with same name in the server.
    i am pasting the code here. please help:
    <!-- uploading the file -->
    <%
    String contentType = request.getContentType();
    if ((contentType != null) && (contentType.indexOf("multipart/form-data") >= 0))
    DataInputStream in = new DataInputStream(request.getInputStream());
    int formDataLength = request.getContentLength();
    byte dataBytes[] = new byte[formDataLength];
    int byteRead = 0;
    int totalBytesRead = 0;
    while (totalBytesRead < formDataLength)
    byteRead = in.read(dataBytes, totalBytesRead, formDataLength);
    totalBytesRead += byteRead;
    String contextRootPath = this.getServletContext().getRealPath("/");
    contextRootPath=contextRootPath.concat("uploaded");
    String file = new String(dataBytes);
    String saveFile = file.substring(file.indexOf("filename=\"") + 10);
    saveFile = saveFile.substring(0, saveFile.indexOf("\n"));
    saveFile = saveFile.substring(saveFile.lastIndexOf("\\") + 1,saveFile.indexOf("\""));
    // Create a directory; all ancestor directories must exist
    File outputFile = new File(contextRootPath, saveFile);
    var=outputFile.getPath();
    outputFile.createNewFile();
    int lastIndex = contentType.lastIndexOf("=");
    String boundary = contentType.substring(lastIndex + 1,contentType.length());
    int pos;
    pos = file.indexOf("filename=\"");
    pos = file.indexOf("\n", pos) + 1;
    pos = file.indexOf("\n", pos) + 1;
    pos = file.indexOf("\n", pos) + 1;
    int boundaryLocation = file.indexOf(boundary, pos) - 4;
    int startPos = ((file.substring(0, pos)).getBytes()).length;
    int endPos = ((file.substring(0, boundaryLocation)).getBytes()).length;
    FileOutputStream fileOut = new FileOutputStream(outputFile);
    fileOut.write(dataBytes, startPos, (endPos - startPos));
    fileOut.flush();
    fileOut.close();
    outputFile.deleteOnExit();
    %>Please help. Thanks for taking time.
    Regards,
    Ashvini

    Thank you MartinHilpert,
    I have one more doubt,
    I am uploading the file to one folder called "uploaded". Before uploading a fresh file, i want to delete all existing files in that folder. IS that possible ?? If yes, can you please tell me how to do that ??
    Regards, Thanks for your time.
    Ashlvini

  • I am sending a single-page poster in Illustrator to a commercial printer. There are several placed graphics and I want to choose the correct file-type to keep my Illustrator file nice and small.

    I am sending a single-page poster in Illustrator to a commercial printer. There are several placed graphics and I want to choose the correct file-type to keep my Illustrator file nice and small.

    Printers like PDFs, but you should consult with the print vendor before you save the file in any particular format.  Each vendor is different and have an established workflow.  They may not accept JPGs.  If the poster prints offset, you will need to supply the appropriate resolution per their request or what they require. If the poster is large format or grand format, then they will or should know what resolution is appropriate.  However, large format inkjet only requires 144-150ppi at 100% final size.  Try to get in the habit of consulting with the print vendor early on so you end up supplying what is needed.

  • When I try to same an image under the command 'save as' it will only let me save as file types 'firefox document' or 'all files' and when I try to look at them later they dont work. How can I save an image as the same file type it is on the web site?!

    When I try to save an image under the command 'save as' it will only let me save as file types 'firefox document' or 'all files' and when I try to look at them later they dont work. How can I save an image as the same file type it is on the web site?!
    == This happened ==
    Every time Firefox opened
    == I updated to one of the firefox versions (Not sure which one it was)

    Thanks Alex, but sadly I already tried that. Neither .docx or .xlsx files show up in the content list. They both show as a Chrome HTML document so changing how Firefox addresses those doesn't help since it thinks its the same type of file. I don't think I can manually add files into the "Content Type" left side nav.

  • Can I change the default 'File Type' for PL/SQL Source File to '*.prc' ?

    Want to change the 'default' extension for PL/SQL source to '*.prc'
    When navigating 'File' / 'Save As', and selecting the 'File Type' list box,
    The default 'File Type' for PL/SQL Source File is '*.pls'.
    Can I change the default 'File Type' for PL/SQL Source File to '*.prc' ?
    I have followed , 'Tools', 'Preferences' , 'File Types' and added '.prc' as 'Sql Script' file type, because (PL/SQL Source) is not present in the list.

    You can certainly overwrite the 'Save As' extension as you are saving the file. I have added an ER for more control over this functionality.
    sue

  • Check for filesize before uploading the file

    Hi everyone,
    I�m currently thinking about a solution to the following question and would need some help:
    I wanna write a small jsf-application where it�s possible to upload files from the client to a server. But I have the problem, that I want to check the filesize of the user-selected file before he starts to upload the complete file, so that I can decide dynamically if it is allowed to upload a file of that filesize . If I simply use the mulipart/form-data-request I always get the complete request and can only decide afterwards if it was too big or not. That�s not the way a wanna go.
    Does anyone know of a good solution to this problem? I guess I won�t be the first one who has to handle with that kind of problem.
    Many thanks
    Thomas

    This can only be done with a client side script. Javascript with ActiveX can do, but in the latest browsers this is disabled by security reasons.
    Locally you might try:<html>
        <head>
            <script>
                function getFileSize(filePath) {
                    var fileSystemObject = new ActiveXObject("Scripting.FileSystemObject");
                    var file = fileSystemObject.getFile(filePath);
                    var size = file.size;
                    alert(size + " bytes\n" + (size / 1024) + " KB\n" + (size / 1024 / 1024) + " MB");
            </script>
        </head>
        <body>
            <form name="myForm">
                <input type="file" name="myFile">
                <input type="button" value="check size" onclick="getFileSize(document.myForm.myFile.value);">
            </form>
        </body>
    </html>This works in IE only and doesn't work in FF 2.0 here.
    I don't know any other solutions as such scripts are forbidden for security reasons.

  • Scan a file for virus before upload

    In many CRM functions, eg - Activities, Mkt Planner, etc., there is a tab for uploading/attaching files.  How can we scan the file for virus before saving?  We have a Basis 620, so we can't use the Virus Scan Interface because it is available from Basis 640 onwards.
    I am looking for two things - 1. A method to scan for virus and 2. A user exit where this can be implemented before saving.
    Thanks.

    http://forum.java.sun.com/thread.jspa?threadID=499566&tstart=200

  • How to limit the file types to be uploaded to KM folders?

    We need to restrict files uploaded to KM to the following types: *.pdf, *.doc, *.ppt, and *.xls.  Uploading the other file types will need to give user an error message. 
    1) Is there a configuration to satisfy this requirement?
    2) If not, what is the work-around? How to we achive this goal?       
    For example:
    1. Go to u2018Private Documents and Discussionsu2019 hyper link.
    2. Click on Owner.
    3. Click on 'Send E-mail' hyperlink
    4. Click on the 'Browse' button, selects a file (with .exe extension)
    5. Click on 'Open' button and 'Upload' button (would like to give user an error message at this point)
    Thank you so much for your help.  I have searched the forum but did not find any specific answers to this issue.

    Hello,
    I have the same problem, unfortunatelly there's no standard way to do this and developing
    custom repository services or upload commands may not attend totally my requirements.
    An idea is to create FSDB CM Repositories or to map external File System repositories for
    specifics needs, so once the documents are stored into a file system (windows in my case)
    it's simple to implement the organization's policy, be it file types, maximum folder size, clean-up routines, etc..
    However there are pros and cons, some services are not available and there are some restrictions,
    here's more detailed information: http://help.sap.com/saphelp_nw04/helpdata/en/62/468698a8e611d5993600508b6b8b11/frameset.htm
    As for the original folders on DB mode, we've been running KM detailed reports once a week
    and deleting the "illegal" files found
    kind regards,
    Rafael

  • Will EC support setting default file type and Open With from file menu?

    The default file types I can live without, but at least allow for Open With on right click from Windows Explorer.
    I currently have EC set in the Open With programs list, but EC does not comply for any files I opt to open it with (.css, .php, .html etc).
    EC open but not the file I choose.
    Also, even though the above use case is not ideal when if I do attempt an Open With when EC is already open, a new application session starts instead of attempting to open in the currently active app frame. It would be ideal to allow for single app frame, multiple files when Open With is employed.
    Darrell

    Hey Darrell,
    Thanks for the feedback. How Edge Code treats files is definitely something we know isn't ideal and it's something we're looking at fixing soon. There's currently a story on the Brackets backlog that adresses the Open With issue - https://trello.com/c/GhF1Bgf9
    And it based on howit ranks in that priority it looks like we could potentially take that into Edge Code over the next couple of months.
    This is definitely a feature that we think is important before we consider ourselves 1.0 so it's high priority.
    =Ryan
    [email protected]

  • Customize File Browse...upload many files at once

    Hi,
    I've searched the forums and this appears to not be possible using the HTMLDB app builder. Some threads I searched include :
    Upload Multiple Files
    Basically, our testing machine will create a folder for each test, inside of which are many files always with the same name. It'd be nice if the user only had to select either the folder, or one file in the folder, and any other files needed in that folder would be automatically uploaded by either HTMLDB or some custom code.
    There were some links as to how the guts of the File Browse... does it's thing in adding files to the flow_files table, but many of the links were dead. Java script can do some custom error checking, but how about behind-the-scenes multiple file loading?
    Just curious if this has been implemented. Running Oracle 9.2.0.4, HTMLDB 1.6.1.00.02.
    Thanks much,
    Matt

    Matt,
    I'm not aware of any way to do this using HTML and Javascript only running in a browser. As such, I don't know of a way to do this using HTML DB. Thing is, web browsers take great care to protect your file system from Javascript running behind the scenes.
    Sergio

  • File type changed to Unix Executable File

    Hello:
    I restored a corrupt Word file from a back-up drive (files are backed up using a special rsync that splits data and metadata forks. I did not assemble the two forks before copying the file back to the production volume) into a production folder in a local machine. Now when I browse the volume from my networked computer all Word files without extensions show up as Unix Executable Files. I've cleared the Launch services in the networked machine with no results. If I browse from other networked computers file types are set correctly. The problem seems to be with this specific networked machine. What an I do to restore file types as they should be? Please, note the problem seems to be with the client machine not the file server.

    Thanks, Kappy. I've tried that but I get an error message saying "An error ocurred while changing...because not enough information is available." Could that mean that the action cannot be done because these files don't have extensions? When I go ahead and select to use Word to always open the file it only takes effect on that file. But the file remains a Unix Executable file.
    Could anyone provide any further help with this issue?
    Message was edited by: Karkula

  • How to filter the file type and size when uploadind files into APEX

    Hi,
    I was wondering how I can do to validate the size of a file, before moving it to my table ? I'd like to filter the file type, but for this one, I think I can use regular expressions in a validation process.
    I don't know if there is a way to read the file size even before sending it into the temporary file table.
    Thank you
    Leinad

    Hello Leinad,
    AFAIK, you have to create an APEX validation (PL/SQL returns Boolean or Returns error text), which will query the file details from apex_flow_files table. Here you can get filetype and size etc.
    So just validate and if any validation fails, then delete the file from apex_flow_files and riase error message.
    Regards,
    Hari
    P.S. Please note that, if there are other apex validations on your page and if they fail, still apex will load the file into apex_flow_files table. So it's good idea to create a validation (PL/SQL) which will fire (condition) when inline validation errors occured. Make sure that this is the LAST validation on your page in sequence. And here you can write code to delete the file from apex_flow_files table.
    Edited by: Hari_639 on Sep 20, 2012 10:09 PM

  • XI30 File Adapter - check for (NOT) incoming file

    Hi!
    We use XI30 SPS15 and have the following challenge: We expect every
    week on a certain day a file coming from a customer. So far so good.
    But now we want to check whether such a file has really come within a
    given period of time and if not, we want to take some action (e.g.
    trigger Alert or s.th. like that).
    Business Background is: If the customer does not send the file or he
    sends it too late, we cannot bill him in time, thus increasing our DSO.
    Is there any mechanism within the XI to check things like these and to
    trigger an alert? I've read the File Adapter Documentation as well as
    the BPM documentation but I could not find any hint.
    Any help would be great. Thanx!
    Regards,
    Volker kolberg

    hi volker,
    this is not supported in standard but...
    you can do it very easily with standard ABAP job scheduling
    - you schedule a job (every week, day etc.)
    which starts a raport that send a RFC (or abap proxy call to the XI)
    - then the RFC starts a BPM and inside it triggers a
    java proxy that checks for a file
    - if the proxy finds the file then if copies it to some other folder (which is monitored by another flow)
    - if it doesn't find the file it triggers an error - sends mail or anything
    the only thing you need to code is a few lines in java
    to check the existance of a file + copying nothing else:)
    this is the easiest way I believe till now <= Sp15
    Regards,
    michal
    <a href="/people/michal.krawczyk2/blog/2005/06/28/xipi-faq-frequently-asked-questions">XI FAQ - Frequently Asked Questions</a>

  • How to add new file type in the xmp allowed files list

    I have to embed metadatas in files that are not listed in the xmp compatible format ( 3D files like dae or obj).
    Is it possible to describe metadatas in  a "sidecar" .xmp files and ask Bridge to embed this metadatas when uploading the files to a Dam ( e.g. Adobe CQ) like what is possible with Digital Photography raw formats, and is handled by Lightroom ?
    Thanks

    Hi,
    In general it is not possible to use Bridge to embed sidecar XMP information into files like Lightroom is doing it. And Bridge only supports metadata read/write in those formats and in those ways as are defined in the XMP specification.
    But you can use the latest XMP SDK to write your own handlers for file formats that are currently not supported. Those file handlers can then be used in either your own application that uses the XMP SDK or any Adobe Video application like Premiere or After Effects to read/write sidecar files or embed XMP metadata into the files. Currently it is not possible to use those file handler plug-ins in other Adobe image applications like Bridge or Photoshop.
    Please see the XMPFiles Custom File-Handler Plug-in SDK for more information.
    Please note that other applications (like CQ) might probably not automatically pick up the metadata you wrote into the file or in a sidecar file, as the other application might probably not have the "knowledge" or technical means to handle metadata in such file formats where you wrote the metadata in a custom way.
    Regards
    Jörg
    Adobe XMP

  • Checking filename length in File Browse item before uploading

    I have a File Browse item from which users can upload files into the database. Within APEX, the file metadata and content first get uploaded into the view WWV_FLOW_FILES. By design apparently, the underlying table for this view has a NAME field which is limited to 90 characters. I would like to test the length of the Name field and provide a warning to the user if the name exceeds 90 characters, but any validation I write to that effect does not "fire" until after the file has been uploaded to the WWV_FLOW_FILES view. That attempt to upload apparently is the first thing that happens when you Submit with a File Browse item, even before the validation. If the name of the file exceeds 90 characters in length, the attempted upload errors out with a generic Page Not Found error. Is there any way to capture the length of the Name of the file with a File Browse item prior to the attempt to upload to the WWV_FLOW_FILES view, or is my only option just to put a warning banner on the page?

    Hello Mike,
    >> Column NAME in WWV_FLOW_FILES is VARCHAR2(90). It does not include the local filename path. It include a prefix like "F1521676842/" in the front of the filename.
    Yes, you are correct. I spoke from memory, and it seems that I remembered one of my customized tables, where I also save the local full path of the file.
    As far as I can see in my system, the extension of the ‘F123….’ is not with a fix length, and the highest one is 18 characters long. Therefore, it seems that the actual file name should be less than 70 characters long.
    A similar code to the following can be used in a validation check:
    <script type="text/javascript">
    function checkFileName(pThis){
      if (pThis.value != "") {
         //get path value (including file name)
         var fileAndPath = pThis.value;
         //find the index of the last "\"
         var lastPathDelimiter = fileAndPath.lastIndexOf("\\");
        //get everything after the last "\"
        var fileNameOnly = fileAndPath.substring(lastPathDelimiter+1);
        if (fileNameOnly.length >70) {
          alert("File name " + fileNameOnly +
              " is too long (" + fileNameOnly.length + " characters).");
          pThis.focus();
    </script>The “HTML Form Element Attributes” of the item should include:
    onblur=" checkFileName(this)"
    Regards,
    Arie.

Maybe you are looking for

  • TRM: Put document number in the field

    I want to put the document number in the field of TRM. The user cannot enter the field. The System need to say what document will processed. I too need to put others two fields in a dynpro. It's possible?

  • How to assign DOT ( current context ) to a variable ?

    If i use XML dot (.) within Href , i am getting current context (http://servername/test) Like this --> <TD> <xsl:element name="a"> <xsl:attribute name="href">./</xsl:attribute> <xsl:value-of select="NAME" /> </xsl:element> </TD> But if i try to assig

  • Bridge icons disappear on PlayBook - paired with BBB 9700

    Hi, I have a BB Bold 9700 with a version 6.0 OS.  My new PlayBook happily paired with the BB, and the Bridge apps appeared in the Home view.  However: - they only show in the All folder, and do not appear in the BlackBerry Bridge folder; - once I hav

  • Migration Procedure for NMS4.15p7(NDS4.16) to iMS5.2(IDS5.1)

    Hello, I'm lost in this matter, because the sun documentation is too confusing concerning this procedure.My question is: Can i migrate from Netscape Messaging Server 4.15 Patch7 using Netscape Directory Server 4.16 to iPlanet Messaging Server 5.2 wit

  • What is the meaning of error message ORA-12545

    Hi! I tried to access oracle through my program "passw.cgi". When the proram run locally, it works well. But when I used internet to invoke "passw.cgi", it could not run and give the error message ORA-12545. I did not know what's wrong with my progra