From 074785cea106179cb3305637055ab0a009ca74f2 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:42:52 -0500 Subject: initial commit --- files/pt-pt/web/api/file/file/index.html | 71 +++++++++++++ files/pt-pt/web/api/file/filename/index.html | 37 +++++++ files/pt-pt/web/api/file/filesize/index.html | 37 +++++++ files/pt-pt/web/api/file/getasbinary/index.html | 77 ++++++++++++++ files/pt-pt/web/api/file/getasdataurl/index.html | 67 ++++++++++++ files/pt-pt/web/api/file/getastext/index.html | 83 +++++++++++++++ files/pt-pt/web/api/file/index.html | 101 ++++++++++++++++++ files/pt-pt/web/api/file/lastmodified/index.html | 113 +++++++++++++++++++++ .../pt-pt/web/api/file/lastmodifieddate/index.html | 80 +++++++++++++++ files/pt-pt/web/api/file/mozfullpath/index.html | 17 ++++ files/pt-pt/web/api/file/name/index.html | 74 ++++++++++++++ files/pt-pt/web/api/file/type/index.html | 75 ++++++++++++++ .../web/api/file/webkitrelativepath/index.html | 80 +++++++++++++++ 13 files changed, 912 insertions(+) create mode 100644 files/pt-pt/web/api/file/file/index.html create mode 100644 files/pt-pt/web/api/file/filename/index.html create mode 100644 files/pt-pt/web/api/file/filesize/index.html create mode 100644 files/pt-pt/web/api/file/getasbinary/index.html create mode 100644 files/pt-pt/web/api/file/getasdataurl/index.html create mode 100644 files/pt-pt/web/api/file/getastext/index.html create mode 100644 files/pt-pt/web/api/file/index.html create mode 100644 files/pt-pt/web/api/file/lastmodified/index.html create mode 100644 files/pt-pt/web/api/file/lastmodifieddate/index.html create mode 100644 files/pt-pt/web/api/file/mozfullpath/index.html create mode 100644 files/pt-pt/web/api/file/name/index.html create mode 100644 files/pt-pt/web/api/file/type/index.html create mode 100644 files/pt-pt/web/api/file/webkitrelativepath/index.html (limited to 'files/pt-pt/web/api/file') diff --git a/files/pt-pt/web/api/file/file/index.html b/files/pt-pt/web/api/file/file/index.html new file mode 100644 index 0000000000..a785c59a41 --- /dev/null +++ b/files/pt-pt/web/api/file/file/index.html @@ -0,0 +1,71 @@ +--- +title: File.File() +slug: Web/API/File/File +tags: + - API + - Construtor + - File API + - Referencia +translation_of: Web/API/File/File +--- +
{{APIRef("File")}}
+ +

O construtor File() cria uma instância do objeto {{domxref("File")}}.

+ +

Sintaxe

+ +
new File(bits, name[, options]);
+ +

Parâmetros

+ +
+
bits
+
Uma {{jsxref("Array")}} de objetos {{jsxref("ArrayBuffer")}}, {{domxref("ArrayBufferView")}}, {{domxref("Blob")}}, {{domxref("USVString")}}, ou um misto de tais objetos, que será posto no {{domxref("File")}}. Objetos USVString são codificados em UTF-8.
+
name
+
Uma {{domxref("USVString")}} que representa o nome do ficheiro ou o caminho para o ficheiro.
+
options {{optional_inline}}
+
Um objeto com atributos opcionais para o ficheiro. As opções disponíveis são: +
    +
  • type: Uma {{domxref("DOMString")}} que representa o tipo MIME do conteúdo será posto no ficheiro. Tem um valor pré-definido de "".
  • +
  • lastModified: Um número que representa o número de milissegundos entre o início da era Unix e a última data em que o ficheiro foi modificado. Tem um valor pré-definido de {{jsxref("Date.now()")}}.
  • +
+
+
+ +

Exemplo

+ +
var file = new File(["foo"], "foo.txt", {
+  type: "text/plain",
+});
+ +

Especificações

+ + + + + + + + + + + + + + + + +
EspecificaçãoEstadoComentários
{{SpecName('File API')}}{{Spec2('File API')}}Definição inicial
+ +

Compatibilidade

+ + + +

{{Compat("api.File.File")}}

+ +

Ver também

+ + diff --git a/files/pt-pt/web/api/file/filename/index.html b/files/pt-pt/web/api/file/filename/index.html new file mode 100644 index 0000000000..0e0ee197ae --- /dev/null +++ b/files/pt-pt/web/api/file/filename/index.html @@ -0,0 +1,37 @@ +--- +title: File.fileName +slug: Web/API/File/fileName +tags: + - API + - DOM + - Ficheiros + - File API + - Non-standard + - Obsoleto + - Propriedade + - Referencia +translation_of: Web/API/File/fileName +--- +
{{APIRef("File API")}}{{non-standard_header}} {{obsolete_header(7.0)}}
+ +

Retorna o nome do ficheiro. Por razões de segurança o caminho é excluído desta propriedade.

+ +
Esta propriedade está obsoleta. Use antes {{domxref("File.name")}}.
+ +

Sintaxe

+ +
var name = instanceOfFile.fileName;
+ +

Valor

+ +

Uma string

+ +

Especificação

+ +

Não faz parte duma especificação.

+ +

Ver também

+ + diff --git a/files/pt-pt/web/api/file/filesize/index.html b/files/pt-pt/web/api/file/filesize/index.html new file mode 100644 index 0000000000..e17676ecee --- /dev/null +++ b/files/pt-pt/web/api/file/filesize/index.html @@ -0,0 +1,37 @@ +--- +title: File.fileSize +slug: Web/API/File/fileSize +tags: + - API + - DOM + - Ficheiros + - File API + - Non-standard + - Obsoleto + - Propriedade + - Referencia +translation_of: Web/API/File/fileSize +--- +

{{APIRef("File API") }}{{non-standard_header}} {{deprecated_header(7.0)}}

+ +

Retorna o tamanho do ficheiro em bytes.

+ +
Esta propriedade está obsoleta. Use antes {{domxref("Blob.size")}}.
+ +

Sintaxe

+ +
var size = instanceOfFile.fileSize;
+ +

Valor

+ +

Um número.

+ +

Especificação

+ +

Não faz parte de nenhuma especificação.

+ +

Ver também

+ + diff --git a/files/pt-pt/web/api/file/getasbinary/index.html b/files/pt-pt/web/api/file/getasbinary/index.html new file mode 100644 index 0000000000..8ec42cf1f2 --- /dev/null +++ b/files/pt-pt/web/api/file/getasbinary/index.html @@ -0,0 +1,77 @@ +--- +title: File.getAsBinary() +slug: Web/API/File/getAsBinary +tags: + - API + - Ficheiros + - File API + - Non-standard + - Obsoleto + - Referencia + - metodo +translation_of: Web/API/File/getAsBinary +--- +

{{APIRef("File API")}}

+ +

{{non-standard_header}}

+ +

{{obsolete_header(7.0)}}

+ +

Sumário

+ +

O método getAsBinary permite aceder aos dados de um ficheiro num formato raw binário.

+ +
+

Nota: Este método é obsoleto; use antes o método {{domxref("FileReader.readAsBinaryString()","readAsBinaryString()")}} ou {{domxref("FileReader.readAsArrayBuffer()","readAsArrayBuffer()")}} de {{domxref("FileReader")}}.

+
+ +

Sintaxe

+ +
var binary = instanceOfFile.getAsBinary();
+ +

Retorna

+ +

Uma string.

+ +

Exemplo

+ +
// fileInput é um HTMLInputElement: <input type="file" id="myfileinput" multiple>
+var fileInput = document.getElementById("myfileinput");
+
+// files é um objeto de FileList (parecido ao NodeList)
+var files = fileInput.files;
+
+// objeto com os tipos de media permitidos
+var accept = {
+  binary : ["image/png", "image/jpeg"],
+  text   : ["text/plain", "text/css", "application/xml", "text/html"]
+};
+
+var file;
+
+for (var i = 0; i < files.length; i++) {
+  file = files[i];
+
+  // se o ficheiro pode ser detetado
+  if (file !== null) {
+    if (accept.binary.indexOf(file.type) > -1) {
+      // file contem dados binarios, num formato permitido
+      var data = file.getAsBinary();
+    } else if (accept.text.indexOf(file.type) > -1) {
+      // file contem texto, num formato permitido
+      var data = file.getAsText();
+      // modificar dados com métodos de string
+    }
+  }
+}
+ +

Especificação

+ +

Não pertence a nenhuma especificação.

+ +

Ver também

+ + diff --git a/files/pt-pt/web/api/file/getasdataurl/index.html b/files/pt-pt/web/api/file/getasdataurl/index.html new file mode 100644 index 0000000000..e3e5bae4b3 --- /dev/null +++ b/files/pt-pt/web/api/file/getasdataurl/index.html @@ -0,0 +1,67 @@ +--- +title: File.getAsDataURL() +slug: Web/API/File/getAsDataURL +tags: + - API + - Ficheiros + - File API + - Non-standard + - Obsoleto + - Referencia + - metodo +translation_of: Web/API/File/getAsDataURL +--- +
{{APIRef("File API") }}
+ +

{{non-standard_header}}

+ +

{{deprecated_header(7.0)}}

+ +

Sumário

+ +

O método getAsDataURL retorna um URL em estilo data: que codifica todo o conteúdo do ficheiro em questão.

+ +
+

Nota: Este método está obsoleto: use antes o método  {{domxref("FileReader.readAsDataURL","readAsDataURL()")}} de {{domxref("FileReader")}}.

+
+ +

Sintaxe

+ +
var url = instanceOfFile.getAsDataURL();
+ +

Retorna

+ +

Uma string a representar um URL de estilo data:

+ +

Exemplo

+ +
// fileInput é um HTMLInputElement: <input type="file" id="myfileinput" multiple>
+var fileInput = document.getElementById("myfileinput");
+
+// files é um objeto FileList (parecido ao NodeList)
+var files = fileInput.files;
+
+// accept é um array com tipos de ficheiros aceites
+var accept = ["image/png"];
+
+// img é um HTMLImgElement: <img id="myimg">
+var img = document.getElementById("myimg");
+
+// se aceitamos o primeiro tipo de ficheiro selecionado
+if (accept.indexOf(files[0].mediaType) > -1) {
+  // apresentar a imagem
+  // igual a <img src="data:image/png,<imagedata>">
+  img.src = files[0].getAsDataURL();
+}
+
+ +

Especificação

+ +

Não pertence a nenhuma especificação.

+ +

Ver também

+ + diff --git a/files/pt-pt/web/api/file/getastext/index.html b/files/pt-pt/web/api/file/getastext/index.html new file mode 100644 index 0000000000..b20229737e --- /dev/null +++ b/files/pt-pt/web/api/file/getastext/index.html @@ -0,0 +1,83 @@ +--- +title: File.getAsText() +slug: Web/API/File/getAsText +tags: + - API + - Ficheiros + - File API + - Non-standard + - Obsoleto + - Referencia + - metodo +translation_of: Web/API/File/getAsText +--- +

{{APIRef("File API") }}{{non-standard_header}}

+ +

{{obsolete_header(7.0)}}

+ +

Sumário

+ +

O método getAsText oferece os dados do ficheiro num formato de texto de acordo com uma codificação.

+ +
+

Note: Este método está obsoleto; use antes o método {{domxref("FileReader.readAsText()","readAsText()")}} de {{domxref("FileReader")}}.

+
+ +

Sintaxe

+ +
var str = instanceOfFile.getAsText(encoding);
+ +

Parâmetros

+ +
+
encoding
+
Uma string a indicar qual a codificação para usar nos dados devolvidos. Se o string estiver vazio, é utilizado UTF-8.
+
+ +

Retorna

+ +

A string que contem os dados do ficheiro num formato de texto especificado pelo encoding.

+ +

Exemplo

+ +
// fileInput é um HTMLInputElement: <input type="file" id="myfileinput" multiple>
+var fileInput = document.getElementById("myfileinput");
+
+// files é um objeto de FileList (parecido ao NodeList)
+var files = fileInput.files;
+
+// object com os formatos de media validos
+var accept = {
+  binary : ["image/png", "image/jpeg"],
+  text   : ["text/plain", "text/css", "application/xml", "text/html"]
+};
+
+var file;
+
+for (var i = 0; i < files.length; i++) {
+  file = files[i];
+
+  // se o formato do ficheiro foi detetado
+  if (file !== null) {
+    if (accept.text.indexOf(file.mediaType) > -1) {
+      // file contem texto, num formato permitido
+      // make sure it's encoded as utf-8
+      var data = file.getAsText("utf-8");
+      // modificar dados com métodos de string
+
+    } else if (accept.binary.indexOf(file.mediaType) > -1) {
+      // binario
+    }
+  }
+}
+ +

Especificação

+ +

Não pertence a nenhuma especificação.

+ +

Ver também

+ + diff --git a/files/pt-pt/web/api/file/index.html b/files/pt-pt/web/api/file/index.html new file mode 100644 index 0000000000..43e85438cb --- /dev/null +++ b/files/pt-pt/web/api/file/index.html @@ -0,0 +1,101 @@ +--- +title: File +slug: Web/API/File +tags: + - API + - File API + - Interface + - NeedsTranslation + - Reference + - TopicStub + - Web +translation_of: Web/API/File +--- +
{{APIRef}}
+ +

The File interface provides information about files and allows JavaScript in a web page to access their content.

+ +

File objects are generally retrieved from a {{DOMxRef("FileList")}} object returned as a result of a user selecting files using the {{HTMLElement("input")}} element, from a drag and drop operation's {{DOMxRef("DataTransfer")}} object, or from the mozGetAsFile() API on an {{DOMxRef("HTMLCanvasElement")}}.

+ +

A File object is a specific kind of a {{DOMxRef("Blob")}}, and can be used in any context that a Blob can. In particular, {{DOMxRef("FileReader")}}, {{DOMxRef("URL.createObjectURL()")}}, {{DOMxRef("ImageBitmapFactories.createImageBitmap()", "createImageBitmap()")}}, and {{DOMxRef("XMLHttpRequest", "", "send()")}} accept both Blobs and Files.

+ +

See Using files from web applications for more information and examples.

+ +

{{InheritanceDiagram}}

+ +

Constructor

+ +
+
{{DOMxRef("File.File", "File()")}}
+
Returns a newly constructed File.
+
+ +

Instance properties

+ +
+
{{DOMxRef("File.prototype.lastModified")}} {{ReadOnlyInline}}
+
Returns the last modified time of the file, in millisecond since the UNIX epoch (January 1st, 1970 at Midnight).
+
{{DOMxRef("File.prototype.lastModifiedDate")}} {{Deprecated_Inline}} {{ReadOnlyInline}}
+
Returns the last modified {{JSxRef("Date")}} of the file referenced by the File object.
+
{{DOMxRef("File.prototype.name")}}{{ReadOnlyInline}}
+
Returns the name of the file referenced by the File object.
+
{{DOMxRef("File.prototype.webkitRelativePath")}} {{Non-standard_Inline}} {{ReadOnlyInline}}
+
Returns the path the URL of the {{DOMxRef("File")}} is relative to.
+
+ +

File implements {{DOMxRef("Blob")}}, so it also has the following properties available to it:

+ +
+
{{DOMxRef("File.prototype.size")}} {{ReadOnlyInline}}
+
Returns the size of the file in bytes.
+
{{DOMxRef("File.prototype.type")}} {{ReadOnlyInline}}
+
Returns the MIME type of the file.
+
+ +

Instance methods

+ +

The File interface doesn't define any methods, but inherits methods from the {{DOMxRef("Blob")}} interface:

+ +
+
{{DOMxRef("Blob.prototype.slice()", "Blob.prototype.slice([start[, end[, contentType]]])")}}
+
Returns a new Blob object containing the data in the specified range of bytes of the source Blob.
+
{{DOMxRef("Blob.prototype.stream()")}}
+
Transforms the File into a {{DOMxRef("ReadableStream")}} that can be used to read the File contents.
+
{{DOMxRef("Blob.prototype.text()")}}
+
Transforms the File into a stream and reads it to completion. It returns a promise that resolves with a {{DOMxRef("USVString")}} (text).
+
{{DOMxRef("Blob.prototype.arrayBuffer()")}}
+
Transforms the File into a stream and reads it to completion. It returns a promise that resolves with an {{DOMxRef("ArrayBuffer")}}.
+
+ +

Specifications

+ + + + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName('File API', "#file-section", "The File interface")}}{{Spec2('File API')}}Initial definition.
+ +

Browser compatibility

+ + + +

{{Compat("api.File")}}

+ +

See also

+ + diff --git a/files/pt-pt/web/api/file/lastmodified/index.html b/files/pt-pt/web/api/file/lastmodified/index.html new file mode 100644 index 0000000000..9b05f6f3cf --- /dev/null +++ b/files/pt-pt/web/api/file/lastmodified/index.html @@ -0,0 +1,113 @@ +--- +title: File.lastModified +slug: Web/API/File/lastModified +tags: + - API + - Ficheiros + - File API + - Propriedade + - Referencia +translation_of: Web/API/File/lastModified +--- +
{{APIRef("File")}}
+ +

A propriedade read-only File.lastModified indica a ultima data em que o ficheiro foi modificado, na forma do numero de milissegundos desde o início da era Unix (1 de janeiro de 1970 às 00:00:00). Os ficheiros cuja a data da última modificação não é conhecida devolvem a data actual.

+ +

Sintaxe

+ +
const tempo = instanciaDeFicheiro.lastModified;
+
+ +

Valor

+ +

Um número que representa o número de milissegundos desde o início da época do Unix.

+ +

Exemplo

+ +

Leitura a partir da entrada do ficheiro

+ +
<input type="file" multiple id="entradaDeFicheiro">
+
+ +
const entradaDeFicheiro = document.querySelector('#entradaDeFicheiro');
+entradaDeFicheiro.addEventListener('change', (event) => {
+  // ficheiros é um objeto de FileList (semelhante a NodeList)
+  const ficheiros = event.target.files;
+
+  for (let ficheiro of ficheiros) {
+    const data = new Date(ficheiro.lastModified);
+    console.log(`${ficheiro.name} tem uma última data modificada de ${data}`);
+  }
+});
+
+ +

Veja os resultados abaixo:

+ +

{{ EmbedLiveSample('Leitura_a_partir_da_entrada_do_ficheiro', 300, 50) }}

+ +

Ficheiros criados dinamicamente

+ +

Se um objeto File for criado dinamicamente, a última data modificada pode ser fornecida na função construtor {{domxref("File.File()", "new File()")}}. Se estiver em falta, lastModified herda a hora actual de {{jsxref("Date.now()")}} no momento em que o objeto File é criado.

+ +
const ficheiroComData = new File([], 'file.bin', {
+  lastModified: new Date(2017, 1, 1),
+});
+console.log(ficheiroComData.lastModified); //devolve 1485903600000
+
+const ficheiroSemData = new File([], 'file.bin');
+console.log(ficheiroSemData.lastModified); //devolve data atual em milissegundos
+
+ +

Reduced time precision

+ +

To offer protection against timing attacks and fingerprinting, the precision of someFile.lastModified might get rounded depending on browser settings.
+ In Firefox, the privacy.reduceTimerPrecision  preference is enabled by default and defaults to 20us in Firefox 59; in 60 it will be 2ms.

+ +
// reduced time precision (2ms) in Firefox 60
+someFile.lastModified;
+// 1519211809934
+// 1519211810362
+// 1519211811670
+// ...
+
+
+// reduced time precision with `privacy.resistFingerprinting` enabled
+someFile.lastModified;
+// 1519129853500
+// 1519129858900
+// 1519129864400
+// ...
+
+ +

In Firefox, you can also enabled privacy.resistFingerprinting, the precision will be 100ms or the value of privacy.resistFingerprinting.reduceTimerPrecision.microseconds, whichever is larger.

+ +

Especificações

+ + + + + + + + + + + + + + + + +
EspecificaçãoEstadoComentários
{{SpecName('File API', '#file-attrs', 'lastModified')}}{{Spec2('File API')}}Definição inicial.
+ +

Compatibilidade

+ + + +

{{Compat("api.File.lastModified")}}

+ +

Ver também

+ + diff --git a/files/pt-pt/web/api/file/lastmodifieddate/index.html b/files/pt-pt/web/api/file/lastmodifieddate/index.html new file mode 100644 index 0000000000..10d5d8c932 --- /dev/null +++ b/files/pt-pt/web/api/file/lastmodifieddate/index.html @@ -0,0 +1,80 @@ +--- +title: File.lastModifiedDate +slug: Web/API/File/lastModifiedDate +tags: + - API + - Ficheiros + - File + - File API + - Obsoleto + - Propriedade + - Read-only + - Referencia + - lastDateModified +translation_of: Web/API/File/lastModifiedDate +--- +
{{APIRef("File API") }} {{deprecated_header}}
+ +

A propriedade read-only File.lastModifiedDate devolve a ultima data em que o ficheiro foi modificado. Ficheiros onde a ultima data de modificação é desconhecida devolvem a data atual.

+ +

Sintaxe

+ +
var time = instanceOfFile.lastModifiedDate
+ +

Valor

+ +

Um objeto Date a indicar a data e hora da ultima modificação ao ficheiro.

+ +

Exemplo

+ +
// fileInput é um HTMLInputElement: <input type="file" multiple id="myfileinput">
+var fileInput = document.getElementById("myfileinput");
+
+// files é um objeto de FileList (parecido ao NodeList)
+var files = fileInput.files;
+
+for (var i = 0; i < files.length; i++) {
+  alert(files[i].name + " has a last modified date of " + files[i].lastModifiedDate);
+}
+ +

Precisão reduzida

+ +

Para oferecer proteção contra timing attacks e fingerprinting a precisão de someFile.lastModifiedDate.getTime() pode ser arredondada dependente das preferências no navegador.

+ +

No Firefox, a preferência privacy.reduceTimerPrecision está ligada por pré-definição com valores arredondados aos 20μs mais próximos no Firefox 59; e no Firefox 60 aos 2ms.

+ +
// precisão reduzida (2ms) no Firefox 60
+someFile.lastModifiedDate.getTime();
+// 1519211809934
+// 1519211810362
+// 1519211811670
+// ...
+
+
+// precisão reduzida com a `privacy.resistFingerprinting` ligada
+someFile.lastModifiedDate.getTime();
+// 1519129853500
+// 1519129858900
+// 1519129864400
+// ...
+
+ +

No Firefox, também pode ligar a preferência privacy.resistFingerprinting, a precisão será arredondada aos 100ms mais próximos ou ao valor de privacy.resistFingerprinting.reduceTimerPrecision.microseconds, o que for maior.

+ +

Especificações

+ +

Apesar de estar presente numa versão inicial do esboço do File API spec, esta propriedade foi removida e agora é non-standard. Use antes {{domxref("File.lastModified")}}.

+ +

Compatibilidade

+ +
+ + +

{{Compat("api.File.lastModifiedDate")}}

+
+ +

Ver também

+ + diff --git a/files/pt-pt/web/api/file/mozfullpath/index.html b/files/pt-pt/web/api/file/mozfullpath/index.html new file mode 100644 index 0000000000..24e126847f --- /dev/null +++ b/files/pt-pt/web/api/file/mozfullpath/index.html @@ -0,0 +1,17 @@ +--- +title: File.mozFullPath +slug: Web/API/File/mozFullPath +tags: + - API + - Ficheiros + - File + - File API + - Non-standard + - Propriedade + - Referencia + - mozFullPath +translation_of: Web/API/File/mozFullPath +--- +
{{APIRef("File API")}}{{draft}}{{Non-standard_header}}
+ +

Uma extensão privilegiada para a interface {{domxref("File")}}, a propriedade mozFullPath contém o caminho completo do ficheiro representado. Esta propriedade só está disponível a partir do código do navegador ou de extensões Firefox ao estilo antigo com base no XPCOM. Não está disponível para o conteúdo da web.

diff --git a/files/pt-pt/web/api/file/name/index.html b/files/pt-pt/web/api/file/name/index.html new file mode 100644 index 0000000000..907a08a8e2 --- /dev/null +++ b/files/pt-pt/web/api/file/name/index.html @@ -0,0 +1,74 @@ +--- +title: File.name +slug: Web/API/File/name +tags: + - API + - File API + - Files + - Propriadade + - Referencia +translation_of: Web/API/File/name +--- +
{{APIRef("File API")}}
+ +
Devolve o nome do ficheiro representado por um objeto {{domxref("File")}}. Por razões de segurança, o caminho é excluído desta propriedade.
+ +

Sintaxe

+ +
var name = file.name;
+ +

Valor

+ +

Uma string, que contem o nome do ficheiro sem o caminho, por exemplo "O meu Resumo.rtf".

+ +

Exemplo

+ +
<input type="file" multiple onchange="processSelectedFiles(this)">
+
+ +
function processSelectedFiles(fileInput) {
+  var files = fileInput.files;
+
+  for (var i = 0; i < files.length; i++) {
+    alert("Filename " + files[i].name);
+  }
+}
+ +

Veja os resultados abaixo:

+ +

{{ EmbedLiveSample('Exemplo', 300, 50) }}

+ + + +

Especificações

+ + + + + + + + + + + + + + + + +
EspecificaçãoEstadoComentário
{{SpecName('File API', '#file-attrs', 'name')}}{{Spec2('File API')}}Definição inicial.
+ +

Compatibilidade

+ +
+ + +

{{Compat("api.File.name")}}

+
+ +

Ver também

+ + diff --git a/files/pt-pt/web/api/file/type/index.html b/files/pt-pt/web/api/file/type/index.html new file mode 100644 index 0000000000..2b448d3086 --- /dev/null +++ b/files/pt-pt/web/api/file/type/index.html @@ -0,0 +1,75 @@ +--- +title: File.type +slug: Web/API/File/type +tags: + - API + - Ficheiros + - File API + - Propriedade + - Referencia + - Tipo de Ficheiro +translation_of: Web/API/File/type +--- +
{{APIRef("File API")}}
+ +

Retorna a média (MIME) representado por um objeto {{domxref("File")}}.

+ +

Sintaxe

+ +
var name = file.type;
+ +

Valor

+ +

Uma string, que contem o tipo de média (MIME) que indica o tipo do ficheiro, por exemplo "image/png" é devolvido para imagens PNG.

+ +

Exemplo

+ +
<input type="file" multiple onchange="showType(this)">
+
+ +
function showType(fileInput) {
+  var files = fileInput.files;
+
+  for (var i = 0; i < files.length; i++) {
+    var name = files[i].name;
+    var type = files[i].type;
+    alert("Filename: " + name + " , Type: " + type);
+  }
+}
+ +
+


+ Nota: Baseado na atual implementação, navegadores não leem a bytestream dum ficheiro para determinar a sua média. É feito uma ilação baseada na extensão do ficheiro; uma imagem PNG com uma extensão ".txt" é atribuída o tipo "text/plain" e não "image/png". Além disso, file.type é geralmente fiável apenas para ficheiros comuns como imagens, documentos HTML, áudio e vídeo. Extensões de ficheiros pouco comuns devolveriam uma cadeia de caracteres vazia. A configuração do cliente (por exemplo, o Registo do Windows) pode resultar em valores inesperados mesmo para tipos comuns. Os programadores são aconselhados a não confiar nesta propriedade como o único esquema de validação.

+
+ +

Especificações

+ + + + + + + + + + + + + + + + +
EspecificaçãoEstadoComentário
{{SpecName('File API', '#dfn-type', 'type')}}{{Spec2('File API')}}Definição inicial
+ +

Compatibilidade

+ + + +

{{Compat("api.File.type")}}

+ +

Ver também

+ + diff --git a/files/pt-pt/web/api/file/webkitrelativepath/index.html b/files/pt-pt/web/api/file/webkitrelativepath/index.html new file mode 100644 index 0000000000..35f155c1c6 --- /dev/null +++ b/files/pt-pt/web/api/file/webkitrelativepath/index.html @@ -0,0 +1,80 @@ +--- +title: File.webkitRelativePath +slug: Web/API/File/webkitRelativePath +tags: + - Ficheiro +translation_of: Web/API/File/webkitRelativePath +--- +

{{APIRef("File API")}}

+ +

O File.webkitRelativePath é uma propriedade só de leitura que contém um {{domxref("USVString")}} que especifica o caminho do ficheiro em relação ao diretório selecionado pelo utilizador num elemento {{HTMLElement("input")}} com o seu conjunto de atributos {{htmlattrxref("webkitdirectory", "input")}}.

+ +

Sintaxe

+ +
 relativePath = File.webkitRelativePath
+ +

Valor

+ +

Um {{domxref("USVString")}} que contem o caminho do ficheiro relativo ao diretório dos antepassados que o utilizador selecionou.

+ +

Exemplo

+ +

Neste exemplo, é apresentado um seletor de diretórios que permite ao utilizador escolher um ou mais diretórios. Quando o evento {{event("change")}} ocorre, é gerada e apresentada uma lista de todos os ficheiros contidos dentro das hierarquias de diretórios selecionados.

+ +

Conteúdo HTML

+ +
<input type="file" id="seletorDeFicheiros" name="listaDeFicheiros" webkitdirectory multiple />
+<ul id="listagem"></ul>
+ +

Conteúdo JavaScript

+ +
document.getElementById("seletorDeFicheiros").addEventListener("change", function(event) {
+  let output = document.getElementById("listagem");
+  let ficheiros = event.target.files;
+
+  for (let i = 0; i < ficheiros.length; i++) {
+    let item = document.createElement("li");
+    item.innerHTML = ficheiros[i].webkitRelativePath;
+    output.appendChild(item);
+  };
+}, false);
+
+ +

Resultado

+ +

{{ EmbedLiveSample('Example') }}

+ +

Especificações

+ + + + + + + + + + + + + + + + +
EspecificaçãoEstadoComentário
{{ SpecName('File System API', '#dom-file-webkitrelativepath', 'webkitRelativePath') }}{{ Spec2('File System API') }}Definição inicial.
+ +

Esta IPA não tem especificação oficial do W3C ou do WHATWG.

+ +

Compatibilidade

+ + + +

{{Compat("api.File.webkitRelativePath")}}

+ +

Ver também

+ + -- cgit v1.2.3-54-g00ecf