# Как сохранять и загружать файлы на Google Collaboratory с локальной машины?

**Внимание! Данное руководство для маленьких файлов: весов модели, трех-четырех картинок. Для работы с большими файлами или наборами данных мы рекомендуем подключить Google Drive к Google Collaboratory.**

За передачу данных с локальной машины на Google Collaboratory отвечает модуль `files`. Импортируйте его для начала работы:

```python
from google.colab import files
```

Теперь для загрузки файлов в память Google Collaboratory можно вызвать следующий код

```python
uploaded = files.upload()
```

`uploaded` - это словарь, его ключи соответствуют именам загруженных файлов. Допустим, что загруженный файл называется 1.png на локальной машине. Вывести содержимое загруженного файла на печать или сохранить файл на диск можно с помощью следующих команд.

```python
print(uploaded['1.png'])
with open('./temp.png', 'wb') as fl: 
    fl.write(uploaded['1.png'])
```

Загрузить файл с диска на локальную машину можно следующим кодом:

```python
files.download('./temp.png')
```

![Автор: Ушенин Константин](/files/-LmV16Hi3oFFG84RsvB6)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://aibm.gitbook.io/prosto-o-glubokom-obuchenii/tekhnicheskie-voprosy/kak-sokhranyat-i-zagruzhat-faily-na-google-collaboratory-s-lokalnoi-mashiny.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
