Restricting file type in Box Content Uploader

回答済み
新規投稿

コメント

5件のコメント

  • 正式なコメント
    Kourtney

    Hello! 

    The best approaches are to:

    • add the requestIntercepter to throw an error if a user tires to upload any file types you do not want to allow
    • using the accept attribute on the input file field

    Hope this helps! 

    Best,

    Kourtney, Box Developer Advocate

    コメントアクション パーマリンク
  • DPL Admin

    Hi Kourtney,

    Thanks for the response! How would you go about using the accept attribute on the input file field? I don't see the Content Uploader accepting any properties related to extensions or an <input> element being used in the code.

    0
    コメントアクション パーマリンク
  • DPL Admin

    I've implemented the requestInterceptor to throw an error, but the ContentUploader continues to retry uploading the files. Is there a way to stop the upload based on the thrown error?

    0
    コメントアクション パーマリンク
  • DPL Admin

    For anyone who needs to restrict file extensions in the future, our solution was to parse the file extension from the filename located in config.data.name and if it was not one of our accepted extensions, we would null out the folder id the file is getting uploaded to (config.data.parent.id = null). There was a very tricky error with this though. Since the file upload to Box is chunked, the config object does not always contain the filename. So you must wrap your parsing of the extension in an if statement to check if the filename is present: if (!!config?.data?.name). If you don't do this, the upload will keep trying until it fails and nothing about this error will be logged to the console.

    0
    コメントアクション パーマリンク
  • Hassan (externe) EL HAYANI

    Hello DPL Admin,

    I use API BOX in my project , and i want to upload only the file with the type "PDF",

    but i don't know how to do it.

    Is there a way to restrict the file types allowed to be uploaded ?

    0
    コメントアクション パーマリンク

投稿コメントは受け付けていません。