我有一个Django应用程序,其视图接受要上载的文件.使用Django REST框架我将APIView子类化并实现post()方法,如下所示:
class FileUpload(APIView):
permission_classes = (IsAuthenticated,)
def post(self, request, *args, **kwargs):
try:
image = request.FILES['image']
# Image processing here.
return Response(status=status.HTTP_201_CREATED)
except KeyError:
return Response(status=status.HTTP_400_BAD_REQUEST, data={'detail' : 'Expected image.'})
Run Code Online (Sandbox Code Playgroud)
现在我正在尝试编写几个单元测试以确保需要身份验证并且实际处理了上载的文件.
class TestFileUpload(APITestCase):
def test_that_authentication_is_required(self):
self.assertEqual(self.client.post('my_url').status_code, status.HTTP_401_UNAUTHORIZED)
def test_file_is_accepted(self):
self.client.force_authenticate(self.user)
image = Image.new('RGB', (100, 100))
tmp_file = tempfile.NamedTemporaryFile(suffix='.jpg')
image.save(tmp_file)
with open(tmp_file.name, 'rb') as data:
response = self.client.post('my_url', {'image': data}, format='multipart')
self.assertEqual(status.HTTP_201_CREATED, response.status_code)
Run Code Online (Sandbox Code Playgroud)
但是当REST框架尝试对请求进行编码时,这会失败
Traceback (most recent call last):
File "/home/vagrant/.virtualenvs/myapp/lib/python3.3/site-packages/django/utils/encoding.py", line 104, in force_text
s = six.text_type(s, encoding, errors)
UnicodeDecodeError: …
Run Code Online (Sandbox Code Playgroud) 当我在Android Studio中运行检测测试时,我发现应用程序之后仍然在设备上.但是我无法从使用gradlew的命令行中做到这一点.我的目的是运行测试,保存例如/ data/data/MyApp/cache/screenshots中的屏幕截图,然后下载这些屏幕截图adb pull
.
./gradlew connectedAndroidTest
Run Code Online (Sandbox Code Playgroud)
导致应用程序被卸载.我也试过了
./gradlew connectedAndroidTest -x uninstallAndroidTest
Run Code Online (Sandbox Code Playgroud)
但这没有任何区别.导致卸载的原因是什么,我该如何避免?
我想知道是否可以使用curl来仅显示响应头的内容类型.
我想在下载下载文件的instate之前检查内容类型是否为text/html,然后找出它是application/pdf.
我使用下面的例子,希望如果它对我有效,它会返回文件,否则什么都不做!下面的示例只打印页面的完整内容.
curl -F "type=text/html" www.google.nl
Run Code Online (Sandbox Code Playgroud)
但是,如果我做类似下面的例子,它仍然下载整个事情,我不认为这是正确的...
curl -F "type=text/html" http://www.axmag.com/download/pdfurl-guide.pdf
Run Code Online (Sandbox Code Playgroud)
非常感谢:D
我有一个照片库应用程序有一个问题为ios 8做好准备.图像显示在UIPageViewController中,每个页面都有一个带有自定义UIScrollView类的视图.这就像Apples PhotoScroller Sample(https://developer.apple.com/library/ios/samplecode/PhotoScroller/Introduction/Intro.html)
我添加了一个UITapGestureRecognizer进行双击.这是我用于缩放的代码:
- (void)scrollViewDoubleTapped:(UITapGestureRecognizer*)recognizer {
if (self.minimumZoomScale == self.maximumZoomScale) return;
if (self.zoomScale == self.minimumZoomScale) didDoubleTap = NO;
CGPoint pointInView = [recognizer locationInView:_zoomView];
CGFloat newZoomScale;
if (!didDoubleTap && self.zoomScale <= self.minimumZoomScale) {
newZoomScale = self.zoomScale * 2.5f;
newZoomScale = MIN(newZoomScale, self.maximumZoomScale);
didDoubleTap = YES;
}
else {
newZoomScale = self.minimumZoomScale;
didDoubleTap = NO;
}
CGSize scrollViewSize = self.bounds.size;
CGFloat w = scrollViewSize.width / newZoomScale;
CGFloat h = scrollViewSize.height / newZoomScale;
CGFloat x = pointInView.x - (w …
Run Code Online (Sandbox Code Playgroud) 因此,由于某些二进制视频文件,我一直在将问题推送到我一直在工作的主分支。当我第一次尝试推送它们时,这些文件太大了。所以我将它们从我正在处理的项目目录中删除。但是现在,当我从第一次初始推送开始尝试推送时,它会返回此错误消息。
Compressing objects: 100% (38/38), done.
Writing objects: 100% (39/39), 326.34 MiB | 639.00 KiB/s, done.
Total 39 (delta 16), reused 0 (delta 0)
remote: error: GH001: Large files detected.
remote: error: Trace: b7371dc6457272213ca1f568d9484c49
remote: error: See http://git.io/iEPt8g for more information.
remote: error: File themes/SomeFile/uploads/me_582610_mountain-river.mov is 315.08 MB; this exceeds GitHub's file size limit of 100 MB
To git@github.com:UserName/Project.git
Run Code Online (Sandbox Code Playgroud)
它说的文件太大,似乎仍然存在于我的目录中,甚至在我的计算机上实际上根本不存在。我把它彻底删除了。这里有什么问题?这是我第一次遇到这个问题。我去了引用的 Git 站点寻求支持,https://help.github.com/articles/working-with-large-files/,然后运行它git rm --cached me_582610_mountain-river.mov
并返回消息fatal: pathspec 'me_582610_mountain-river.mov' did not match any files
请任何帮助将不胜感激!