使用雾上传和下载文件时,我已经看到了几种不同的方法。哪个更受欢迎,哪个更重要?
上传
#include "stdafx.h"
#include <iostream>
#include <math.h>
#include <SFML/Graphics.hpp>
using namespace std;
using namespace sf;
int main()
{
float xo = 250;//координаты центра(coordinates of the center)
float yo = 250;//координаты центра(coordinates of the center)
float radius = 10;//радиус
float k = 0.0f;//время(time)
float x = 130;//координаты объекта(object coordinates)
float y = 330;//координаты объекта(object coordinates)
float rotation = 5.0;
/*float x = 1000 / 2;
float y = 1000 / 2;*/
float alpha = 0;//угол(angle)
float speed = 200.0f;
RenderWindow window(sf::VideoMode(1000, 1000), "Atom");
window.setFramerateLimit(60);
Clock clock;
sf::Event windowEvent;
Texture herotexture;
herotexture.loadFromFile("atom_image.png");
Sprite herosprite;
herosprite.setTexture(herotexture);
//herosprite.setTextureRect(IntRect(0, 99, 48, 51));//получили нужный нам прямоугольник с котом
herosprite.setPosition(250, 250); //выводим спрайт в позицию x y (output the sprite to the position x y)
CircleShape circle;
circle.setRadius(radius);
circle.setOutlineColor(Color::Red);
circle.setOutlineThickness(5);
circle.setPosition(x, y);
circle.setRotation(0);
while (window.isOpen())
{
Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
/*circle.rotate(rotation);
alpha = (float)clock.getElapsedTime().asMicroseconds() * k;*/
float Radius = sqrt(pow(((float)circle.getPosition().x - (float)herosprite.getPosition().x), 2.0f) + pow(((float)circle.getPosition().y - (float)herosprite.getPosition().y), 2.0f));
clock.restart();
k = k / 800;
float deltaTime = clock.restart().asSeconds();
alpha += deltaTime*(float)clock.getElapsedTime().asSeconds();
cout << "\nGet Position Atom is -> " << (float)herosprite.getPosition().x << endl;
cout << "\nGet Position Circle is -> " << (float)circle.getPosition().x << endl;
cout << "\nRadius is -> " << Radius << endl;
x = xo + Radius*cos(alpha) * speed;//формула для движения по окружности(formula for motion along a circle)
y = yo + Radius*sin(alpha) * speed;//формула для движения по окружности(formula for motion along a circle)
cout << "x is -> " << x << endl;
Vector2f direction(x, y);
circle.move(direction * deltaTime * speed);
if (sqrt(pow(((float)circle.getPosition().x - (float)herosprite.getPosition().x), 2.0f) + pow(((float)circle.getPosition().y - (float)herosprite.getPosition().y), 2.0f)) > (float)herosprite.getPosition().x && sqrt(pow(((float)circle.getPosition().x - (float)herosprite.getPosition().x), 2.0f) + pow(((float)circle.getPosition().y - (float)herosprite.getPosition().y), 2.0f)) > (float)herosprite.getPosition().y)
{
circle.move(-direction * deltaTime * speed);
float cd = circle.getPosition().x + 40;
circle.move(cd, circle.getPosition().y);
circle.setPosition(130, 330);
}
/*circle.move(direction);
circle.move(x, y);*/
window.clear();
window.draw(herosprite);
window.draw(circle);
window.display();
}
return 0;
}
或
directory.files.create(key: local_filename,
body: File.open(local_path),
public: false)
和下载我只有一个例子,但需要将文件选项更改为&#39; wb&#39;让它工作:
下载
connection.put_object(directory.key,
local_filename,
File.open(local_path),
public: false)
答案 0 :(得分:1)
很棒的问题。
directory.files.create
版本最终会调用connection.put_object
,因此在功能上它们在基本用法上应该是等效的。话虽如此,directory.files.create
是首选方案,因为它允许您(在许多情况下)更改您正在使用的存储提供商并拥有东西&#34;只是工作&#34; (即使在该提供者上载的方法看起来完全不同)。
在下载方面,应该有一个类似directory.files.get
vs connection.get_object
类型的区别来获取对象的引用。您需要directory
版本,然后像您一样调用body
方法,应该根据需要为您提供内容。
希望澄清一下。