hugo/content/en/methods/resource/Data.md
Bjørn Erik Pedersen 9b0050e9aa Squashed 'docs/' content from commit 5c085a37b
git-subtree-dir: docs
git-subtree-split: 5c085a37b297bf12f59efeaae591418ec025c10d
2024-01-27 10:48:33 +01:00

1.2 KiB

title description categories keywords action
Data Applicable to resources returned by the resources.GetRemote function, returns information from the HTTP response.
related returnType signatures
functions/resources/GetRemote
methods/resource/Err
map
RESOURCE.Data

The Data method on a resource returned by the resources.GetRemote function returns information from the HTTP response.

{{ $url := "https://example.org/images/a.jpg" }}
{{ with resources.GetRemote $url }}
  {{ with .Err }}
    {{ errorf "%s" . }}
  {{ else }}
    {{ with .Data }}
      {{ .ContentLength }} → 42764
      {{ .ContentType }} → image/jpeg
      {{ .Status }} → 200 OK
      {{ .StatusCode }} → 200
      {{ .TransferEncoding }} → []
    {{ end }}
  {{ end }}
{{ else }}
  {{ errorf "Unable to get remote resource %q" $url }}
{{ end }}
ContentLength
(int) The content length in bytes.
ContentType
(string) The content type.
Status
(string) The HTTP status text.
StatusCode
(int) The HTTP status code.
TransferEncoding
(string) The transfer encoding.